Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Linux and Unix Linux and Unix
Search Search
Search for:
Tech Support Guy > > >

CRON Help


(!)

burgiuk's Avatar
burgiuk burgiuk is offline
Computer Specs
Junior Member with 2 posts.
THREAD STARTER
 
Join Date: Mar 2011
Experience: Advanced
30-Mar-2011, 07:46 AM #1
CRON Help
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
lotuseclat79's Avatar
Member with 20,583 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
30-Mar-2011, 11:23 AM #2
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
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
burgiuk's Avatar
burgiuk burgiuk is offline
Computer Specs
Junior Member with 2 posts.
THREAD STARTER
 
Join Date: Mar 2011
Experience: Advanced
31-Mar-2011, 07:30 AM #3
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
lotuseclat79's Avatar
Member with 20,583 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
01-Apr-2011, 12:45 PM #4
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

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


Tags
backup, cron, linux

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑