Command scheduling with cron

Posted on: Feb 25th, 2010


Have you ever missed an appointment because you were so absorbed in some thing that you totally lost the track of time? It’s a good thing if you were doing nuclear research at that time you probably didn’t want your link to be broken, but for most of us, missing appointments is a bad thing. What you can do it… Set up reminders on your phone, then again, many people like me don’t always keep checking their phones.  The solution? Learn to use cron jobs. Cron jobs are helpful with your appointments and ‘to-do’s of course, but their real power can only be perceived when you actually start using cron jobs on your servers or workstations to automate backups. Here’s a detailed how-to about the same.

What you will need is, a Linux machine with the cron deamon running and a user account with access to cron jobs. For most new distributions the cron daemon is installed and running by default and users group has access to it.

Now, whenever cron is installed it also creates some directories.

/etc/cron.d
/etc/cron.daily
/etc/cron.hourly
/etc/cron.monthly
/etc/cron.weekly

These directories behave, as the name suggests, on a periodic basis. Any executable script placed inside will run every ‘x’ amount of time (every day, hour, etc). You don’t have to worry about the detailing of the scheduling process.  The time when the scripts run is defined in the /etc/crontab file. You will need root privileges to edit all of these files and directories.

What if you want to specify certain commands with time? Crontab is the answer. As a user, type the command, crontab -l to list the current jobs. Crontab -e will open it in editor. Enter any command/script which you want to schedule in this file and save it.  Crontab has a general formatting of the following type,

  1. The minutes
  2. The hours in 24 hour format
  3. The day of the month
  4. The the number of a month
  5. The day of a week. Either use names or numbers. 0 and 7 both mean Sunday.
  6. The command you wish to execute.

That is, if your files reads,

0 8 * * * sonata play

Then, the music player sonata will run every day of the week, every month at 0800 hours. That’s about it, I recommend you start scheduling your tasks right away!



About the author


Aditya is a Linux fanatic, a nature photographer, a music fiend... He spends most of his time these days listening to Music while browsing the Internet about various topics of his interest ranging from Electronics to coffee recipes.


http://www.noob2geek.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png http://www.noob2geek.com/wp-content/plugins/sociofluid/images/delicious_48.png http://www.noob2geek.com/wp-content/plugins/sociofluid/images/technorati_48.png http://www.noob2geek.com/wp-content/plugins/sociofluid/images/google_48.png http://www.noob2geek.com/wp-content/plugins/sociofluid/images/myspace_48.png http://www.noob2geek.com/wp-content/plugins/sociofluid/images/facebook_48.png http://www.noob2geek.com/wp-content/plugins/sociofluid/images/twitter_48.png

Leave a Reply

Latest Posts

Tags