Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

can someone tell me if this will work?

  • 06-09-2001 9:34am
    #1
    Registered Users, Registered Users 2 Posts: 10,339 ✭✭✭✭


    righty, I've tried to write a batch that executes on the hour. The idea is to get a file that is appended to on another server with the minimum of risk that they try to append it while I am copying the file over.

    so, my solution is to

    rename the file (nice and quick)
    put up a blank version of the original file
    move the renamed file to my server for processing.

    now, my big problem is that this has to be run from a unix server and I know nothing about unix so I've decided to convert what I would do in dos to ftp and from there to sftp and unix. Here's what I've come up with so far:

    chmod wx sftp
    sftp -b [user@host]
    cd [path to file]
    rename [oldname][newname]
    put [oldname - blank file]
    get [newname] - does get "move" or "copy"?
    rename [newname] ["date".txt]
    quit

    now: after this there's a bit of monkeying about with our side of things.

    the scheduling is in the crontab:
    5 0-23/1 * * * [the command to execute]

    the way I see it, this will run at 5 past the hour, every hour.

    questions:
    1. On the last rename, will the "date" rename the file to a timeanddate.txt format?
    such as 120501012001.txt for the file renamed on the 1st of jan 2001 at 12:05? this would be useful for archiving.

    2. Any thoughts on error handling? How can I get the script to run again if the file is being appended to when it tries to rename?

    3. How do I get it to give up after a certain number of retries; useful for if the connection is down?

    4. how do I get it to notify me that it is done or has hit a snag? (I'd be on a win2k system).


Comments

  • Registered Users, Registered Users 2 Posts: 3,744 ✭✭✭deRanged


    ok - two things.
    1) to check that the machine you're ftp'ing to is up you can put something like:
    if ( ping -c 1 MACHINE > /dev/null ) then
    do stuff
    fi

    2) to check if the file is being used you can use the fuser command. (man fuser)


  • Subscribers Posts: 1,911 ✭✭✭Draco


    <font face="Verdana, Arial" size="2">5 0-23/1 * * * [the command to execute]</font>
    5 * * * * [command]
    No need to specify the hour if you're running it hourly.
    <font face="Verdana, Arial" size="2">questions:
    1. On the last rename, will the "date" rename the file to a timeanddate.txt format?
    such as 120501012001.txt for the file renamed on the 1st of jan 2001 at 12:05? this would be useful for archiving.
    </font>
    No. You'll have to grab the date in the script, put it into a variable and then rename the file:
    DATE = `date +%y%m%d%h%M`
    cp myfile myfile.$DATE
    This will copy a file called myfile to myfile.0109061201 (year,month,day,hour,minute).
    Run "man date" for more details on the date command.
    <font face="Verdana, Arial" size="2">
    2. Any thoughts on error handling? How can I get the script to run again if the file is being appended to when it tries to rename?
    </font>
    Erm, not sure.
    <font face="Verdana, Arial" size="2">
    3. How do I get it to give up after a certain number of retries; useful for if the connection is down?
    </font>
    Not sure.
    <font face="Verdana, Arial" size="2">
    4. how do I get it to notify me that it is done or has hit a snag? (I'd be on a win2k system).</font>
    To get it to notify you use the mail command
    e.g echo "this is a test mail" | mail -s "test mail" draco@boards.ie
    This will send "this is a test mail" in a mail with the subject "test mail" to Draco@boards.ie.
    man mail for more details.

    Why the chmod on sftp?
    Rename the file to the current date and time the first time you rename it so you don't have to do it again.



  • Registered Users, Registered Users 2 Posts: 10,339 ✭✭✭✭LoLth


    thanks,

    the chmod is because any tutorials I looked at always started with modifying the executable's rights.. so, monkey see, monkey do.

    nice one with the date thingy, but the system here needs the same filename to be copied over each time (sets off the processing batch, which I'm adding to, to do a copy and rename as well - at the moment there's no archiving so if a file process fails for some reason, the data is lost)


  • Registered Users, Registered Users 2 Posts: 3,744 ✭✭✭deRanged


    so do you want to ftp over two files - the oldfile and a copy of it with the name set to the date?


  • Subscribers Posts: 1,911 ✭✭✭Draco


    <font face="Verdana, Arial" size="2">Originally posted by LoLth:
    the chmod is because any tutorials I looked at always started with modifying the executable's rights.. so, monkey see, monkey do.)</font>
    Ah right. Well, unless some one changes it, you should only have to do it once - if at all. The permissions should be set automattically when sftp is installed.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 10,339 ✭✭✭✭LoLth


    copying two files would be one option I suppose.

    here's what's happening:

    1. file called order.txt is being appended to every time a batch is run on a clients machine that processes email orders taken in.

    2. I want to rename that to [client].txt
    to be pulled across and processed by the server here that autoruns a batch when it finds [client].txt in a local directory. This process deletes the text file.

    3. I want a copy of the file on the client server, and one on our server, so I do a rename and move on their machine (after the get command) and a rename and copy (using the same date variable) on the machine here - before the file gets deleted.

    the idea is that order.txt will always be available for appending to (except when it's getting renamed and the blank file is being "put" onto their machine.. but being blank it shouldn't take long).

    It's the crossover time I'm worried about. That's why I want a way of backing off if the file is being used and retrying later.


Advertisement