[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [K12OSN] Way OT: scripting help



Dimitri Yioulos wrote:

Apologies if my description of what I'm after isn't clear above. I want to make sure our business partner had uploaded it's file to the ftp server, then transfer it, then make sure an exact copy actually did get transfered, then delete the file on the ftp server next day. Does the construct:

while [ ! -e $FILENAME ]

This looks for the specified file in the current directory. If it does not exist ( the ! negates the -e test) you fall into the loop. If the file is there you'll skip past the 'done'. I assume the files have a unique name or you've moved the previous one so the first time through you will execute the loop.

do
rsync -essh othermachine:/path/$FILENAME . || sleep 900

This tries to copy the file to the current directory (.). If it fails for any reason (the likely one being that the file doesn't exist yet) it will wait 900 seconds (15 * 60). The || construct means 'or' and the right side only happens if the left side fails.

done

This loops back to the while test. When the file exists, you move on. You don't have to worry about 'exact' copies. Rsync will use a tmp file name during the transfer and only rename to the real name when the transfer is complete and correct.

wait 15 minutes if the file hasn't been uploaded to the ftp server, then do the tranfer, otherwise do the transfer (doesn't look like it does)? How would I then repeat the rsync to test that the transfer actually happened and, if not (for whatever reason), try the transfer again. Now, I hope I'm not pushing the lists good nature, but how might I log that the transfer took place successfully (doesn't matter whether it on the ftp server or the file server that it's being transferred to)?

Unless you go out of your way to avoid it, cron will send email with the output of the script to the user that set up the job. If you don't mind some uglyness, just add a -v to the rsync command and make sure email works. You could also explicitly log it with something like
echo "$FILENAME arrived at $(date)" >>/path/to/logfile
after the done. The ftp xferlog on the ftp server will also show when it arrived there.

--
  Les Mikesell
   lesmikesell gmail com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]