Schedule a task on Linux – crontab

Scenario:

As a release engineer, you have to schedule a task sometimes. On Windows, you might use Task Scheduler to schedule one. http://windows.microsoft.com/en-us/windows7/schedule-a-task

On Linux platform, it also provides a very elegant tool to schedule tasks. It is crontab.

Solution:

Crontab could empower you to schedule tasks in ‘Minute’ ‘Hour’ ‘Day of Month’ ‘Month’ and ‘Day of week’.

Check below line:

30 * * * * cd /u01/abc ; ./abc.pl parameter=y >> /u01/log/output.log

It means, Linux will run cd to /u01/abc and run script ./abc.pl parameter=y and its output will be appended to  /u01/log/output.log in every 30mins.

And then, you can create a file (supposed its name is cron.txt) and in the text it could contain your lines as below,

30 * * * * cd /u01/abc ; ./abc.pl parameter=y >> /u01/log/output.log

* * * * * cd /u01/def ; ./def.pl parameter=n >> /u01/log/deflog.log

and then issue command:

crontab cron.txt

Done. 🙂

Pls. note, ASA your OS get reboot, you should rerun your crontab.

You can issue command to check your crontab items.

crontab -l

Details, pls check out http://linux.about.com/od/commands/l/blcmdl5_crontab.htm