[K12OSN] Way OT: scripting help

Dimitri Yioulos dyioulos at firstbhph.com
Thu May 24 15:38:48 UTC 2007


On Wednesday 23 May 2007 3:02 pm, Les Mikesell wrote:
> 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 at gmail.com
>
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>

Les,

Hearty thanks to you, Dan, and Huck for your responses.  Looks like your 
suggestions will work fine.  And thanks for the detailed explanation - very, 
very helpful.

OK, now to perhaps earn your scorn and enmity by asking one last question (no, 
really):  If I want to delete all files older than 1 day EXCEPT "somefile", 
what might I do to:

find $WORKDIR -maxdepth 1 -mtime +$DAYSOLD -exec rm {} \;

to accomplish that?

Again, thanks.

Dimitri

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the K12OSN mailing list