+ Post New Thread
Results 1 to 5 of 5
*nix Thread, crontab not working in Technical; Hi, to start here's my crontab on my Ubuntu install: Code: sudo crontab -e Which gives me: Code: # m ...
  1. #1

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241

    crontab not working

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

    Code:
    sudo crontab -e
    Which gives me:

    Code:
    # 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:

    Code:
    #!/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

  2. #2

    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    11,802
    Thank Post
    110
    Thanked 583 Times in 504 Posts
    Blog Entries
    1
    Rep Power
    224
    what crons logfile say? Also, you should be getting email about the failing job, what does that report?

  3. #3

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Quote Originally Posted by Geoff View Post
    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?

  4. #4

    Join Date
    Oct 2008
    Location
    Hedge End, Southampton
    Posts
    56
    Thank Post
    1
    Thanked 10 Times in 10 Posts
    Rep Power
    13
    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:
    Code:
    jim@eros:~$ cat /etc/aliases | grep root:
    root:           serverlogs@wildern.hants.sch.uk
    Then get your mailer to recheck the aliases (only needed if you're using sendmail):
    Code:
    sudo newaliases
    To check the mail on the command line, switch to the user who is getting the mail and run
    Code:
    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):
    Code:
    00 08-18/1 * * * /bin/sh /var/backupscripts/squid.sh

  5. Thanks to james_yale from:

    Hightower (17th March 2009)

  6. #5

    Hightower's Avatar
    Join Date
    Jun 2008
    Location
    Cloud 9
    Posts
    4,920
    Thank Post
    494
    Thanked 690 Times in 444 Posts
    Rep Power
    241
    Quote Originally Posted by james_yale View Post
    add a shell in which to run the script (your cron may not use bash):
    Code:
    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!

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

SHARE:
+ Post New Thread

Similar Threads

  1. strange nic lights working/not working
    By browolf in forum Wireless Networks
    Replies: 13
    Last Post: 15th December 2008, 01:50 PM
  2. It's working! At last
    By localzuk in forum General Chat
    Replies: 4
    Last Post: 10th September 2008, 06:13 PM
  3. No More working!!!!!
    By Scotmk in forum General Chat
    Replies: 2
    Last Post: 23rd July 2008, 12:04 PM
  4. [CLOSED] Bug/Error: Joomla not working
    By Jackd in forum EduGeek.net Site Problems
    Replies: 4
    Last Post: 21st January 2008, 09:49 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •