Schedule a Job


Recommended Posts

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 ?

Link to comment

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.

Link to comment

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 >>"

Link to comment

 

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.

 

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.