backup script
Joel Hammer
joel
Mon May 17 11:57:27 PDT 2004
You may need to have a space between a '[' and the contents of the comparison:
if [$?-eq0]; # Wrong
if [ $? -eq 0 ]; # Right
^ ^
I am not sure if the spaces are needed between the members of the
comparison.
Joel
On Fri, Dec 26, 2003 at 11:14:27PM -0800, Marianne Taylor wrote:
> 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
>
> _______________________________________________
> Linux-users mailing list
> Linux-users at smtp.linux-sxs.org
> Unsubscribe/Suspend/Etc -> http://smtp.linux-sxs.org/mailman/listinfo/linux-users
More information about the Linux-users
mailing list