Linux cron tasks

Cron task is used to automate tasks in Unix/Linux. It is something that you need to trigger commands / scripts @ specific interval of time. It is sort of task scheduler that windows has. But it is much more customizable and is command line based. So lets see how can we add cron tasks.

Lets say we have a shell script that displays nothing but todayz date. It is named and for some reason you want to run it every day @ 00.00 hrs.

The first thing you should know about cron task is the format in which you specify the time for automating your tasks. There are five fields to set the time.

* * * * * <command to execute>

You need to set the five stars as per your requirement. These 5 *s are five fields for

1. minute (0-59)
2. hour (0-23)
3. day (1-31)
4. month (1-12)
5. day of week (0-6, 0 being Sunday)
6. command to execute

So now to execute our file, we need to add the cron task to the system. To do that issue this command:

$ crontab -e

Depending on your login, your cron tasks will differ. So once you are presented with your editor to edit the file, enter the following line:

0 0 * * * /home/user_name/

This will make sure that your shell script runs everyday @ midnight. If you want to run it every 5 minutes, use this instead:

*/5 * * * * /home/user_name/


0 1 29 1 1 /home/user_name/

will help you setup the execution on 1.00 AM, 29th January, Monday. You could also use this for same result….

0 1 29 jan mon /home/user_name/

Once you have entered the time, exit and wait for it to be executed.😀

Cron tasks can be used for several purposes like backing up data, deleting logfiles / temporary files, copying data etc. So unless you have a lot of time to spend in front of your computer for the right moment to trigger commands on your own, I think you shud be using cron tasks.😀

Leave a Reply

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

You are commenting using your 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