LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Script not running after reboot (https://www.linuxquestions.org/questions/linux-general-1/script-not-running-after-reboot-940442/)

norwichnick 04-18-2012 06:57 AM

Script not running after reboot
 
Hi everyone,

I have a Ubuntu 10.04 LTS (Desktop) box that I am trying to backup with a script that's automatically triggered in a user's crontab with limited success.

The script exports data from the local MySQL server, uses GZip to compress it and then uses FTP to send it over the Internet to another computer.

I have tested the file after making it executable, and everything works to plan; there's a local backup of the DB, and the file is received on the remove server - no problem.

My problem comes when scheduling it. I currently have it on a schedule to run every hour at 15 minutes past between 08:15 and 18:15. The entry on my crontab looks as follows:
Code:

15 8 * * 1,2,3,4,5 /full/path/to/script.sh
15 9 * * 1,2,3,4,5 /full/path/to/script.sh
and so on ...

I know that I can use 8-18 and 1-5 to specify hour and day ranges ... This is how it's set out whilst testing.

If I SSH to the box and run the backup as the user that has it on their crontab, it runs fine. The job will then continue to run through until 18:15, and resume again at 08:15.

However, if the box is restarted/powered off; the schedule stops. Going back in to the crontab and saving it doesn't 'rescue' it.

The only thing that seems to rescue it running the script manually whilst connected to SSH. It will then continue to run on schedule as normal.

Any ideas as to what may be causing my insanity?

Any helps is massively appreciated!

All the best,
Nick

pan64 04-18-2012 07:09 AM

I would insert some log into that script, like
Code:

echo scriptname started at >> logfile
date >> logfile
...
echo scriptname finished >> logfile
date >> logfile

also I would try to redirect stdout and stderr of the crontab entry
Code:

15 9 * * 1,2,3,4,5 /full/path/to/script.sh >>/full/path/to/log.stdout 2>>/full/path/to/log.stderr
maybe you can catch some error...

dayid 04-18-2012 07:32 AM

In addition to what pan64 suggested - just a thought:

Do you happen to use encrypted home directories and have the full path of the script as somewhere in the user's home directory? Scripts wouldn't be run because the user's home directory is encrypted, and since the user wasn't logged in, the encrypted home directory was not mounted, thus cron could not access/read the script. However, presuming mail is configured correctly, you'd still receive an error mail about this situation to the user's account.

norwichnick 04-19-2012 03:35 AM

Thank you pan64 and dayid for your replies!

pan64, I shall have to remember to turn on logging when messing around with scripts in the future.

dayid, you've saved my day. I've moved the backup script to /etc and changed where the backup dumps the database files to the same directory and gave it a test run. It worked fine, then I powered down the box at the end of the day. I've turned it on first thing this morning, checked it an hour later, and I have a backup come through that's run perfectly on schedule.

Thank you so much!

All the best,
Nick


All times are GMT -5. The time now is 09:07 AM.