JarDo Posted October 11, 2008 Share Posted October 11, 2008 What is the best way to schedule a job to run at a particular time? I've been running an rsync client for months now by copying the script to the cron.daily folder from my go script. That's worked great, but now I want to add another rsync client job to run daily. The way I figure it if I place the second script in the cron.daily folder they will both run at exactly the same time (4:30am, I think). What I want to do is stagger the two jobs. From what I can tell I can edit the 'root' file in the /var/spool/cron/crontabs directory to accomplish this, but I really don't want to muck with my default installation files. Can I just add my own file to the /var/spool/cron/crontabs directory ? Quote Link to comment
WeeboTech Posted October 11, 2008 Share Posted October 11, 2008 The way I figure it if I place the second script in the cron.daily folder they will both run at exactly the same time (4:30am, I think). files in /etc/cron.day are usually run one at a time. That is... as long as the individual job file in the directory does not run commands in the background with an & sign. If you do a crontab -l you will see a bunch of lines with /usr/bin/run-parts. This is how files in the /etc/cron.xxxxxx directories are processed. you can also place your own job to run via cron. I'll try to find an example. I think there are some on the board. Quote Link to comment
WeeboTech Posted October 11, 2008 Share Posted October 11, 2008 There is an example in the following post on adding a line to crontab without disturbing the unmatched lines. The key is in the proper match with the grep line. http://lime-technology.com/forum/index.php?topic=2116.msg15711#msg15711 Quote Link to comment
JarDo Posted October 11, 2008 Author Share Posted October 11, 2008 Hmmmm... If I understand this part correctly: # Append new entries to root's crontable cat <<-EOF >> /tmp/crontab.root # Daily Automatic /sbin/powerdown 00 23 * * * /sbin/powerdown EOF You are listing the contents of /tmp/crontab.root to a file of the same name (overwriting the original) and keeping it open for additional input until an "EOF" is read? The net result is a /tmp/crontab.root file that is the same as the original plus however many additional lines you wanted to add (in this case one additional line). I'm just trying to follow/understand before I go mucking things up. I've used the cat command many times before but I don't understand the syntax of "<<-EOF >>" Quote Link to comment
WeeboTech Posted October 11, 2008 Share Posted October 11, 2008 crontab -u root -l | grep -v /sbin/powerdown > /tmp/crontab.root list the contents (-l) of user root ( -u root ) to the input of grep (-v except the line /sbin/powerdown) to a file /tmp/crontab.root cat <<-EOF EOF Means read stdin from the next lines HERE until you reach a Line with EOF >> /tmp/crontab.root means append the output of something to a file called /tmp/root.crontab. so I am reading lines from via stdin in the current document until EOF (cat copies files from stdin to stdout) and appending to the pre-existing file /tmp/crontab.root so a cat <<-EOF >> /tmp/crontab.root EOF concatenate lines from stdin here until EOF appending to /tmp/crontab.root. It could have been done with... echo "# Daily Automatic /sbin/powerdown" >> /tmp/crontab.root echo "00 23 * * * /sbin/powerdown" >> /tmp/crontab.root The net effect is the same. The difference is that by doing it in the here document with one output redirection, the output file iis only opened once. It also makes adding lines easier. Just insert in between the cat and the EOF. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.