1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

CRON Help

Discussion in 'Linux and Unix' started by burgiuk, Mar 30, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. burgiuk

    burgiuk Thread Starter

    Joined:
    Mar 30, 2011
    Messages:
    2
    Hello guys

    We have recently setup a linux server at work to use as a web development testing environment. We have this up and running perfectly. We now want to backup the websites and local databases to our main office file server. I have created a script to dump the databases and tar/zip the folders we want to backup. When I run the script manually it works perfectly.
    Code:
    #!/bin/bash
    /usr/bin/clear
    /usr/bin/mysqldump --all-databases -u root -ppassword > /var/www/beastdb.sql
    /usr/sbin/service mysql stop
    /usr/sbin/service apache2 stop
    /sbin/mount.cifs //192.168.16.2/Public /mnt/monkeyfish -o user=user,pass=Password
    /bin/echo PROCESSING TAR!
    /bin/tar czf /mnt/monkeyfish/backup_`date +%Y-%m-%d`.tar.gz /var/www/
    /bin/umount /mnt/monkeyfish
    /usr/sbin/service mysql start
    /usr/sbin/service apache2 start
    /bin/echo DONE
    
    My problem arises when I try to automate the task. I have dropped it in both the /etc/cron.hourly and /etc/cron.daily. The hourly one is for testing only. I have done CHMOD 777 on the file to allow it to execute with no joy.

    I am totally stumped. Any suggestions or ideas are very much welcome.

    Thanks

    John
     
  2. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Hi burgiuk,

    Welcome to TSG!

    When you run the script manually (and it runs perfectly), you are executing it under the auspices of the account you are using with a defined set of environment variables, and permissions for what it does.

    In order to debug the script - just append a "-x" to the first line in the script for the cron job and make sure the cron job specifies an execution log for output so you can find the problems. The first line should look like:
    #!/bin/bash -x

    Initially, try running the script manually again in your terminal window. The try running as follows (again in the terminal window) to save an execution log:

    $ ./script.sh > script.out 2>&1

    When the command finishes executing, the prompt is then available for executing another command. Inspect the log file with an editor or the less command.

    Then setup a similar command to run under the auspices of cron (with same permissions, root, password, etc.). It should tell you what is going wrong with the script as executed from the cron entry when you look at the execution log output.

    Of course, you could scan the system logs for any information that cron may emit.

    -- Tom
     
  3. burgiuk

    burgiuk Thread Starter

    Joined:
    Mar 30, 2011
    Messages:
    2
    Tom

    This is the output I get when I added the -x to the script.
    Code:
    + /usr/bin/mysqldump --all-databases -u root -ppassword
    + /usr/sbin/service mysql stop
    mysql stop/waiting
    + /usr/sbin/service apache2 stop
     * Stopping web server apache2                                                                                                 ... waiting                                                             [ OK ]
    + /sbin/mount.cifs //192.168.16.2/Public /mnt/monkeyfish -o user=user,pass=password
    + /bin/echo PROCESSING 'TAR!'
    PROCESSING TAR!
    ++ date +%Y-%m-%d
    + /bin/tar czf /mnt/monkeyfish/backup_2011-03-31.tar.gz /var/www/
    /bin/tar: Removing leading `/' from member names
    + /bin/umount /mnt/monkeyfish
    + /usr/sbin/service mysql start
    mysql start/running, process 7292
    + /usr/sbin/service apache2 start
     * Starting web server apache2                                           [ OK ]
    + /bin/echo DONE
    DONE
    
    There is no mention of the CRON even running in /var/log/syslog

    John
     
  4. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    Have you setup the cron job to keep a log with the -x on in the script?

    Have you read the man page for cron? There is a log level parameter, -L that can be set.

    -- Tom
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/988821