Friday, February 7, 2014

Running scheduled tasks



Running scheduled tasks


If you are doing a repetitive task on your system, it is better to automate. For example, you may want to sync fi les between two systems at a regular interval. Instead of doing it yourself manually, you can create a scheduled task that automatically runs at the configured intervals. In Linux (and most UNIX environments) this is achieved through cron. Cron is a time-based task scheduler. To create a scheduled tasks using cron…

01 Run the following command to open the
current user’s crontab fi le:
$ crontab -e
If you want a task to be run using root privileges,
you should use the command:
$ sudo crontab –e

02 The crontab fi le will then open in the default
text editor.

The default text editor can be set up using the
EDITOR environment variable:
$ export EDITOR=nano

Crontab takes input in the following format:
minute(0-59) hour(0-23) day(1-31)
month(1-12) weekday(0-6) command

An asterisk ( * ) is used as wild card. For example,
using asterisk with month will cause the task to
run every month.

03 Let’s assume that you want to run /usr/bin/
myludapp every day at 12.30 AM. So we will need
to create the following line in it:
29 0 * * * /usr/bin/myludapp

Here, 29 is for the 30-minute mark and 0 for
12 am because the minute, hour and weekday
values start at 0. However, the day and month
values start at 1 instead of 0.

No comments:

Post a Comment