An extremely terse cron intro

I mentioned cron in the last post, but I think aside from that brief example, I’ve barely ever written about it.

There’s no real reason for that, except that I don’t use it very often and so as a result I don’t mention it. Hopefully the logic in that is clear. :roll:

It’s not too difficult to set up or understand though, and so the example I gave yesterday makes a good starting point. Here are those lines again.

00  * * * * /usr/bin/python /home/kmandla/.xplanet/download_clouds.py /home/kmandla/.xplanet/clouds_2048.jpg
00 23 * * * /usr/sbin/vbetool dpms off
30 06 * * * /usr/sbin/vbetool dpms on

You can edit crontab by entering crontab -e (of all things) and your defined $EDITOR will take over.

The gist of cron -- for me -- is simply this: Those two first numbers are the time you want the action performed, listed in reverse.

So "00 23" is actually 11 p.m., listed minutes first then hour. Every day at 11 p.m., that command is run. And "30 06" is 6:30 a.m.

The "00" without a number, with only a splat next to it, means every hour on the hour. Like I mentioned yesterday, I don't know exactly when the weather maps are updated, so once an hour is probably enough.

Everything I've shown there runs daily, but if I wanted a command run on a particular day of the month, I could list the day number next.

So it should follow that the next column is the month. And the last column? The day of the week, with Sunday as day 0.

That's the long and short of it. You can tell cron to do whatever, whenever via crontab. After restarting cron for good measure, you should be set. So for one last example:

15 05 * * * 6 /usr/bin/yaourt -Syu

Every week at 5:15 a.m. on Saturday, a system-wide update.

If you need more details or if you have a huge slew of commands you want run at the same time check out the Arch wiki page for cron. Once again, the Arch wiki is the best resource around. ...

About these ads

6 thoughts on “An extremely terse cron intro

    1. livibetter

      In my opinion, I would recommend `man 5 crontab`, that’s the best source because every cron program may have some differences between them. (I use vixie-cron)

      And that’s how I learn about how to get rid of `/usr/bin/foo` or `/home/username/bin/bar`, make them to be just `foo` and `bar`.

      PYTHONPATH=”/home/username/lib/python2.5:/usr/local/lib64/python2.6″
      PATH=”/home/username/bin:/usr/bin:/bin”

      I have these lines before my cron table. Additionally, I have

      #Mins Hours Days Months Day of the week

      right above cron jobs, tab-separated valued, so I don’t need to double check every I need edit my table.

      Reply
  1. Pingback: Links 14/2/2011: GNU/Linux Education in Valencia, London Stock Exchange Goes Live With GNU/Linux | Techrights

  2. bmc5311

    cron + rsnapshot (rsync) = poor man’s time machine.

    That’s how I do my backups, hourly, daily, weekly and monthly.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s