crontab not working
Hi, to start here's my crontab on my Ubuntu install:
Which gives me:
The first two jobs appear to work fine - I mean I can view the logs of my squid server. The 3rd line (squid.sh) does not work however. squid.sh is a backup script that copies certain files to a SMB share. It works fine is I manually enter sudo /var/backupscripts/squid.sh so why won't it work in the crontab?
# m h dom mon dow command
00 08-18/1 * * * sarg-reports today
00 00 * * * sarg-reports daily
00 08-18/1 * * * /var/backupscripts/squid.sh
The contents of the backup script are as follows:
I'm not sure what to do to find out why it is failing so any advice in diagnosing this would be appreciated :D
### MySQL Setup ###
### Start Backup for file system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :
tar -zcvf $BACKUP/$FILE $DIRS
### Start MySQL Backup ###
# Get all databases name
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
tar -zcvf $DAY.tgz $BACKUP
### Dump backup using SMB ###
smbclient //xxx.xxx.xxx.xxx/xxx -U xxx%xxx -c "put $DAY.tgz"
rm -rf $BACKUP
rm -rf $DAY.tgz
what crons logfile say? Also, you should be getting email about the failing job, what does that report?
Sorry for being a n00b and asking a stupid question but how do I check the emails?
Originally Posted by Geoff
Email from crontab goes to the user who is running that job - if it's the system crontab that's root. You might want to setup a redirect so you get the mail for root, easy to do edit /etc/aliases and find the root: line, eg:
Then get your mailer to recheck the aliases (only needed if you're using sendmail):
jim@eros:~$ cat /etc/aliases | grep root:
To check the mail on the command line, switch to the user who is getting the mail and run or install something abit more friendly like mutt to read it.
Lastly, is your backup script set as executable? Check that and also optionally add a shell in which to run the script (your cron may not use bash):
00 08-18/1 * * * /bin/sh /var/backupscripts/squid.sh
I added that line and it seems to have done the trick (well it backed up automatically at 10 for the first time).
Originally Posted by james_yale
Thank you! :D
P.S. If you get chance could you explain why I needed that line, so I know for future.