backup script

Marianne Taylor mataylor
Mon May 17 11:57:26 PDT 2004


On December 26, 2003 22:57, Marianne Taylor wrote:
> On December 26, 2003 19:33, Joel Hammer wrote:
> > I would insert some something like this to ensure the command worked:
> >
> > /bin/tar -cvpzf $BACK_DIR/mail-$DATE.tar.gz $MAILDIR
> > [ $? -eq 0 ] && echo "Backup Worked " `date` | mail -s Backup YourAddress
> >
> > ||   echo "Backup Failed " `date` | mail -s Backup YourAddress
> >
> > BTW, I haven't tried these exact commands.
> >
> > Joel
>
> ===trimmed==
>
> Thanks Joel the first part I figured out on my own still testing the second
> part, but good idea.

OK I largely have the script working but am getting an error on line 22 which 
is the the "if statement" line.
Error is "line 22: [: missing `]'"
I can't figure out what is wrong.  Can someone help again?

=============================================================
#!/bin/bash
# This script will backup e-mail nightly when called from cron


# first mount hda2 to store the backup onto
/bin/mount /dev/hda2

# next portion defines the maildir to backup
#this can be expanded as needed
MAILDIR=/home/mataylor/.maildir

#defines the backup directory
BACK_DIR=/mnt/storage/backup/mail

#get date for file name
DATE=$(/bin/date +%F)


#tar command to compress the file - named with date and preserving permissions
/bin/tar -cvfpz $BACK_DIR/mail-$DATE.tar.gz $MAILDIR

if [$?-eq0];
  then echo "E-mail backup worked" $DATE |/usr/sbin/sendmail root
    else echo "Backup of e-mail failed" $DATE |/usr/sbin/sendmail root
  fi

sleep 2m

#un-mount /dev/hda2
/bin/umount /dev/hda2

#End of the script



More information about the Linux-users mailing list