Bash script conditions

Jonathan Duncan jonathan at jkdwebmagic.com
Wed Jul 12 06:22:34 MDT 2006


I have a script that I call with a cron job to do my nightly backups:

-----------------------------------------------------------------
### Variables set above here ###
$RSYNC -az -e ssh --delete --exclude-from=$EXCLUDE $BACKUP1 
$UNAME@$SERVER:$DEST  >>$LOG 2>>$LOG

mv /path/to/files /new/path/to/files

echo 'Backup to server finished at: '`date` >>$LOG
echo '' >>$LOG
echo '--------------------------------------------------' >>$LOG
echo '' >>$LOG
-----------------------------------------------------------------

It works just fine, until there is a problem with rsync (like the 
connection dies, etc.).  This is a problem because immediately following 
the rsync I move the files being rsync'd.

How can I put a condition around the rsync command so that if it fails, 
the move does not run?  I assume something like this should do it:

if (rsync command) {
     do the move command
}

I just do not know the syntax.  I saw a list of "Exit Values" in the rsync 
man page but how do I check for those?

Thanks,
Jonathan


More information about the PLUG mailing list