How to set cron jobs in Linux

Written by Sony on 24 February 2010 in , | 2 Comments

If you are programmer then you many times heard about cron jobs. Who are new in to programming or new about using cron jobs they always think, how schedule job in linux box.

For many purpose we can use the cron jobs. Like sending emails, taking Mysql or database backup, taking file system backup or any other purpose.

What is Cron?

Cron is basically Linux program which will run on only windows.

Cron is a program that enables you to execute a command, or a script with a sequence of commands, at a specified date, time or at set intervals. The commands or scripts that you want cron to run are defined in a file called crontab, and every user has their own independent crontab file. Cron is a system program that is running all the time and is similar to the Windows scheduler which allows you to run commands/programs at predefined times and intervals.

We can pass following parameters to Cron file.

Minute = Minute of the hour, 00 to 59. * Will indicate every minute (details later)
Hour = Hour of the day in 24-hour format, 00 to 23. * Will indicate every hour (details later)
Day = Day of the month, 1 to 31. * Will indicate every day (details later)
Month = Month of the year, 1 to 12. * Will indicate every month (details later)
Day = Day of the week, 3 chars – sun, mon, tue, or numeric (0=sun, 1=mon etc)…. * Will indicate every day (details later)
Task = The command you want to execute

Now I will show you how to use the cron in Linux.

#su

#ROOT PASSWORD

#crontab -e

This will open the corn file from linux

Put you options in this file. For example

* * * * php  /var/www/html/project_name/script.php

Above script will fun after each minute.

00 18 * * php  /var/www/html/project_name/script.php

Above script will run at 6PM of day

More commands about crontab

#crontab -l

This will list cron file and all tasks which are present in cron file.

#crontab -r

This command will delete all cron jobs from cron file.

Using following command will show the all error log about cron file.

#tail -f /log/cron/error_log

Tags: ,

You might also like

How to schedule events in wordpress
How to execute linux commands using php
Which IDE is good for wordpress development
How to Install the IE6 and IE7 on Fedora11
WordPress vs Joomla vs Drupal, Which is more popular and user friendly

2 Responses to “How to set cron jobs in Linux”

  1. I reveal to my buddies that linux Operating system is really much more advanced than Windows xp however it’s unlikely that any of these people have yet swapped!

  2. I so liked reading your website. Awesome content. Please keep posting such profound cotent.

Leave a Reply

Wordpressapi is developer code book.
wordpressapi on Facebook
© 2010 Wordpressapi. All Rights Reserved. Reproduction without explicit permission is prohibited.