On 24/02/2006, at 6:35 , x-unix- request at listserver.themacintoshguy.com wrote: > Hi, > This is rather long, sorry. > > Rather than use a 'third-party' application to do my backups, I have > written a bash script to backup my important files to another > computer on my home lan. Why? Just because I can. > > It's working well, with the exception of a couple of things I would > like some input on. > > First, I'm not satisfied with how I'm verifying that the backup > volume on the remote server is mounted or not. Can anyone help make > that section 'bullet-proof'? > > Second, [...] > > Here is my script... > ***** > #!/bin/bash > > ## NOTE: ADD 'n' TO THE cmd OPTIONS WHEN TESTING > > dc=`date +%m%d%y` > file='/Users/Charles/Documents/backup.log.'$dc'.txt' > cmd='rsync -uvrtp --delete-after' > src=/Users/Charles > dest=/Users/charles/mnt > > # Is the server on? > ping -o -t 5 moe > /dev/null 2>&1 > if [ "$?" -ne 0 ] ; then > # Assume server is not on, display alert and quit > echo "Cannot ping server, exiting" >> $file > mail -s "Weekly Backup results" charles < $file > exit > else > # The server is on, is the backup volume mounted? > if [ `ls /Users/charles/mnt/FreeBSD > /dev/null 2>&1` ] ; then > #Volume is mounted, continue > ... > else > # Volume is not mounted, mount it and continue > mount -t nfs moe:/backup /Users/charles/mnt > /dev/null 2>&1 as proposed, save the return code here > if [ "$?" -eq 0 ] ; then > # Mounted OK > echo `date` > $file > echo >> $file > echo "Mounted volume successfully, continuing." >> $file > echo >> $file > else > # Mount failed > if [ "$?" ! -eq 0 ] ; then use '-ne' instead of '! -eq' '!' tries to negate the following *expression* (c.f. man test) and '- eq 0' isn't an expression, so thigs will go wrong here! If you insist on using '!' then it's '! "$?" -eq 0'. > echo `date` > $file > echo >> $file > echo "Mount returned" "$?" ", exiting." >> $file use the saved return value here > mail -s "Weekly Backup results" charles < $file > exit > fi > fi > fi > fi Robert Departement Informatik FGB tel +41 (0)61 267 14 66 Universität Basel fax. +41 (0)61 267 14 61 Robert Frank Klingelbergstrasse 50 Robert.Frank at unibas.ch CH-4056 Basel Switzerland http:// www.informatik.unibas.ch/personen/frank_r.html