LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   need help setting crontab (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-setting-crontab-479215/)

isuck@linux 08-31-2006 02:33 PM

need help setting crontab
 
this is the output of cat /etc/crontab

Quote:

# m h dom mon dow user command
17 * * * * root run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.daily
47 6 * * 7 root test -x /usr/sbin/anacron || run-parts --report /etc/cron.weekly
52 6 1 * * root test -x /usr/sbin/anacron || run-parts --report /etc/cron.monthly
1 * * * * root root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -config=www.dude -update >/home/elmo/awstats.dude.html
5 2 * * * root root /backup/backup_a
6 2 * * * root root /backup/backup_b
7 2 * * * root root /backup/backup_c
8 2 * * * root root /backup/backup_d
This last 4 lines are suppose to create 4 new files in the /backup folder and they are not working, the cron log is showing that the commands were run but when I browse to check the files created, the 4 backups are not there. The backup scripts work just fine when run from the command line. I need help to do this correctly. Thanks.

gilead 08-31-2006 02:43 PM

If the logs show the scripts being run, but no output is produced, the problem is probably inside the scripts themselves.

Do you use the full path to commands? For example, /usr/bin/tar instead of tar? cron runs with a different environment to a logged in user, paths and environment variables may not be what the script needs.

isuck@linux 08-31-2006 03:47 PM

No, I just had tar without any path, I changed it now to see if it works. Thanks.

isuck@linux 09-01-2006 08:24 AM

I didn't work, I found another thread talking about the same problem and the guys says that he restarted cron and now it works. I will try it to, do you know anything about that?

timmeke 09-01-2006 09:55 AM

If you're referring to http://www.linuxquestions.org/questi...d.php?t=479234,
then your problem is different from the other one. Your cron jobs work just fine and just don't do what they're expected to. The other post is about cron not detecting any changes to the crontab settings, without restarting cron service.

As for your problem, start off by catching any output of your backup script into a file, by modifying the crontab command like this:
(/backup/backup_a 2>&1) > /tmp/backup_a.out
and likewise for the other ones.

If all goes well, you should get at least some clues of what's going wrong (ie error messages in /tmp/backup_a.out).

Most likely, they're related to issues with environment variables like $PATH, similar to the issue with tar.

isuck@linux 09-04-2006 09:34 PM

I tried and then restarted cron to make sure it runs. I tried several times is like the cron weren't reading the file, It did not create any files nor in the backup folder or in tmp/ even thou the log says the script was executed. Any ideas what this could be? thank you again.

timmeke 09-05-2006 03:09 AM

So the script executes but doesn't seem to do anything? Try putting a simple command like "date" or "whoami" at the top. If you then catch stdout in a file (ie in /tmp), you should see at least the output of that command, just to confirm that the script runs fine.
If it does run fine, then the lack of output may be simply due to the executed commands.

isuck@linux 09-05-2006 09:48 AM

5 2 * * * root root (/backup/backup_a 2>&1) >/tmp/a.cron.out
6 2 * * * root root (/backup/backup_b 2>&1) > /tmp/b.cron.out
7 2 * * * root root (/backup/backup_c 2<&1) > /tmp/c.cron.out
8 2 * * * root root (/backup/backup_d 2>&1) > /tmp/d.cron.out
40 8 * * * root root /bin/date > /tmp/date.cron.out

Thats my crontab, it executed the last command and created the file date.cron.out but it was empty, no data inside the file. I also tried it with the 2>&1 in that case no file was created at all. This is starting to piss me off cause I have no clue.

isuck@linux 09-09-2006 06:10 AM

I don't really know cron that good, I fixed it using crontab -e and creating the crontab for root and putting the commands there instead of using the file /etc/crontab, for some reason now it works. Thanks anyways for all your help.

timmeke 09-11-2006 02:05 AM

You're welcome. Glad it works now.


All times are GMT -5. The time now is 08:16 AM.