Backup script won't run in cron job. Why?
I have a simple backup script that I put in /etc/cron.daily. It won't run! However, it runs fine when I do it manually.
Code:
sudo ./backup.cron here is the backup script Code:
#!/bin/sh |
Check the cron log (usually /var/log/cron) for errors.
|
When something runs from the commandline but not from cron, first, suspect environment. Then look into environment problems. Finally, investigate what might be different in the environment!
Joking aside, it's almost always a command you're calling based on something in your PATH, but that PATH environment is not the same under cron. So the command is not found. Maybe it's not even finding the most basic thing - your backup script itself! Or it could be some other environment variable that is missing. Cron gives you a very truncated environment to work with. Occassionally you'll run into a problem where your commandline shell is not the same shell cron gives you by default. I haven't seen this so much under Linux, but under Solaris you can run into issues with /bin/ksh as you commandline and plain old /bin/sh being handed to you by cron. |
Quote:
Quote:
|
What directory is your script in? Try adding that directory to the line:
PATH=/usr/local/bin:/usr/bin:/bin Also I vaguely remember reading that CRON doesn't like files with an extension. Try changing the file name to something like backup_cron. Keith |
Quote:
|
Quote:
Code:
sudo cat syslog.0 | grep cron.daily |
How are you making cron execute the script? Do you have a copy of the script in /etc/cron.daily/, or did you add an entry in the user crontab for some user (e.g. root).
If you entered a line into a user crontab, can you paste that line here? In either case if a program called by cron produces output, that output should be mailed to your admin user, so having local mail delivery working is useful if you've not set that up already. (look in /var/mail to see if there are mail files which you aren't picking up. You'll be able to read them just with less (although it's ugly), or you can point your mail client to the files there and say it's the mbox format - this should split the messages up and format them a little better). Last idea, umm, if you launch from a crontab for a user, try appending "> /tmp/my.log 2>&1", wait for the command to execute and then see what's in this logfile, /tmp/my.log |
You guys won't believe this, but I found the problem. The problem was the filename I gave the script. I called it /etc/cron.daily/backup.cron. I decided to just rename it to /etc/cron.daily/backup and now my daily backups are happening. I don't see why the filename would be the problem, but I guess it is. Very odd! Now my next task is learning how to rsync the data to another remote server on a daily basis.
|
Told you.
Keith |
Quote:
|
I never knew cron had a preference for some names. [checks manual page]
Quote:
|
Yup, learn something new every day. Thanks! :)
|
Glad I could help. I think I picked it up from a random comment on the Ubuntu forums.
Keith |
Quote:
I know this cron limitation/anomoly does not apply to Solaris. I just checked my crontabs on a few of those servers and ALL of my jobs have extensions. Typically *.sh or *.pl Interesting to note that Linux might handle things differently. I must say, I'm surprized by this. What possible reason would there be? |
All times are GMT -5. The time now is 02:08 PM. |