Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

Hi, to start here's my crontab on my Ubuntu install:

 

sudo crontab -e

 

Which gives me:

 

# m h  dom mon dow   command
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
00 08-18/1 * * * sarg-reports today
00 00      * * * sarg-reports daily
00 08-18/1 * * * /var/backupscripts/squid.sh

 

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?

 

The contents of the backup script are as follows:

 

#!/bin/sh

DIRS="/var/www"
BACKUP=/var/backupscripts/backups/backup.$$
NOW=$(date +"%d-%m-%Y")
INCFILE="/root/tar-inc-backup.dat"
DAY=$(date +"%a")

### MySQL Setup ###
MUSER="xxx"
MPASS="xxx"
MHOST="localhost"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"

SMBCLIENT="$(which smbclient)"

### Start Backup for file system ###
[ ! -d $BACKUP ] && mkdir -p $BACKUP || :

SMBD="xxx"
FILE="fs-full-$NOW.tar.gz"
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
do
FILE=$BACKUP/mysql-$db.$NOW-$(date +"%T").gz
$MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE
done

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

 

I'm not sure what to do to find out why it is failing so any advice in diagnosing this would be appreciated :D

Posted
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?

Posted

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:

jim@eros:~$ cat /etc/aliases | grep root:
root:           [email protected]

 

Then get your mailer to recheck the aliases (only needed if you're using sendmail):

sudo newaliases

 

To check the mail on the command line, switch to the user who is getting the mail and run

mail

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

  • Thanks 1
Posted
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).

 

Thank you! :D

 

P.S. If you get chance could you explain why I needed that line, so I know for future.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...