Cron jobs

From PCLinuxOShelp Knowledge Base

Jump to: navigation, search

Crontab Configuration Under Linux

Cron is a time-based job scheduler in Unix-like computer operating systems. The name cron comes from the word “chronos”, Greek for “time”. Cron enables users to schedule jobs to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration, though its general-purpose nature means that it can be used for other purposes, such as backing up important data.

Each cronjob has following syntax:

Cron-syntax.png

command to be executed

STEP 1: Now, Open terminal as a root / normal user and enter the following

crontab -e 1 * * * * /bin/echo "Congratulations...!"

This will echoed “Congratulation…!” every minute and you can see this message in user’s mail box. Save and exit the file.


STEP 2: Restart the cron daemon to make it effective, use the following command service crond restart

What does the line actually mean

crontab -e means to edit the users cron file. Your cron file(s) is located at /var/lib/spool/cron

The '1 * * * *' is the time base. 1 is the number of minutes to be ran. the following '* * * *' are wild cards meaning ALL so we are running this command every one minute of every hour, of every day of the month, every month of the year, and every day of the week.

If the command line is not your cup of tea, there are several good GUI programs for setting up your cron job.

Webmin is a simple way to setup cron. It also is in the Repository.

Webmin.png

So what can cron be used for besides sending out a silly little messages every minute, you ask?
You can use it for almost anything. Only your mind is the limit of the things cron can do.

automate a daily backup send yourself reminders create and keep your own repository up to date

If you can dream it, cron surely can do it!

Personal tools