LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-25-2010, 11:44 AM   #1
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX
Posts: 565

Rep: Reputation: 57
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?
 
Old 03-25-2010, 12:46 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,647

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
Is the file executable?
 
Old 03-25-2010, 01:23 PM   #3
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX
Posts: 565

Original Poster
Rep: Reputation: 57
yes, chmod 0755
 
Old 03-25-2010, 02:05 PM   #4
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,647

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
Is cron.hourly running?
 
Old 03-25-2010, 02:09 PM   #5
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Linux Mint
Posts: 8,511

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
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.
 
Old 03-25-2010, 03:25 PM   #6
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX
Posts: 565

Original Poster
Rep: Reputation: 57
Quote:
Originally Posted by AlucardZero View Post
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.
 
Old 03-25-2010, 03:40 PM   #7
hockeyman_102
Member
 
Registered: Apr 2006
Location: Washington
Distribution: Suse, CentOS, Ubuntu
Posts: 124

Rep: Reputation: 15
Show current cronjobs:
crontab -l

edit cronjobs with default editor:
crontab -e

http://en.wikipedia.org/wiki/Cron
 
Old 03-25-2010, 03:41 PM   #8
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Linux Mint
Posts: 8,511

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
Perhaps you can post the cronjob or script?
 
Old 03-26-2010, 05:03 AM   #9
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
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
 
Old 03-26-2010, 10:36 AM   #10
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX
Posts: 565

Original Poster
Rep: Reputation: 57
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.
 
  


Reply

Tags
bash, cron, job, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
add a job to cron.daily pbxuser911 Linux - Server 9 10-29-2009 12:30 AM
cron.hourly cron.weekly cron.monthly and 0anacron. Are they necessary? glore2002 Debian 2 09-30-2009 08:57 PM
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
script in cron.hourly not running hourly unholy Linux - Software 2 09-19-2006 08:21 PM
How do I run/write an hourly cron? KoopaTroopa Linux - Newbie 1 08-16-2003 06:12 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration