LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   BASH: Add cron job to run hourly (http://www.linuxquestions.org/questions/programming-9/bash-add-cron-job-to-run-hourly-797826/)

worm5252 03-25-2010 12:44 PM

BASH: Add cron job to run hourly
 
Hey guys, I have an rsync script I wrote that I have tested and it works perfectly when I run it manually. Now I am working on a server setup script and I have gotten my setup script to create the rsync script in /etc/cron.hourly and restart crond. To spite the fact that the script is in /etc/cron.hourly and I have restarted crond, the script does not run.

With that said, how can I script adding the rsync script to run hourly as a cron job?

AlucardZero 03-25-2010 01:46 PM

Is the file executable?

worm5252 03-25-2010 02:23 PM

yes, chmod 0755

AlucardZero 03-25-2010 03:05 PM

Is cron.hourly running?

repo 03-25-2010 03:09 PM

Since cron has a limited path, make sure to give the whole path to the commands and files.
Normally root should recieve an email if any problems.
Take a look in the log files for some pointers.

worm5252 03-25-2010 04:25 PM

Quote:

Originally Posted by AlucardZero (Post 3912071)
Is cron.hourly running?


I do not know. I guess I should check that

Quote:

Originally Posted by Repo
Since cron has a limited path, make sure to give the whole path to the commands and files.
Normally root should recieve an email if any problems.
Take a look in the log files for some pointers.

It is a single command and it uses absolute path names so thats not a problem.

hockeyman_102 03-25-2010 04:40 PM

Show current cronjobs:
crontab -l

edit cronjobs with default editor:
crontab -e

http://en.wikipedia.org/wiki/Cron

repo 03-25-2010 04:41 PM

Perhaps you can post the cronjob or script?

PMP 03-26-2010 06:03 AM

Redirect the standard error and stdout to file to capture the out and error log, that will help in moving to the right direction
Code:

* */1 * * * /path/to/script/script 1>>/tmp/script.out 2>>/tmp/script.err

worm5252 03-26-2010 11:36 AM

I got it sorted out. Not sure why it wasn't running but I simply wrote a entry into /etc/crontab and the restarted crond and it works. I know you are supposed to use crontab -e to add jobs but that does it for a user, this way I can script it and have the system run it as root.


All times are GMT -5. The time now is 11:19 AM.