Working with cron

From Oxxus Wiki

Jump to: navigation, search

Cron is a daemon which executes commands and scripts automatically at a precise time.

You can modify the crontab with the following command:

crontab -e

-e is a switch for editing crontab

Some other switches are:

  • -l for listing active crontabs
  • -r for removing a crontab

By default, crontab is modified for a username you are logged in as. You can modify another user's crontab with -u [user] option.

When you have started editing crontab, you need to type in each line cron job you want to be executed.

Sample of the line would be:

0 0 * * * /usr/scripts/checkProcesses

First five characters stand for:

  1. - minutes
  2. - hours
  3. - day in a month
  4. - day in a week
  5. - month in a year

The rest of the line contains the command to be executed or the path to the shell script.

In the example above, the script /usr/scripts/checkProcesses is set to be executed every day at 00:00

To set the script to execute every five minutes, you could use the following line:

*/5 * * * * /usr/scripts/checkProcesses

In this example the minute character is extended with /5 which means every fifth minute literally.

Please note that editing crontab will open vi editor and some basic usage of vi editor is: press i to get into insert mode and write the line, and press esc to exit from insert mode when finished.

To record a file, type:

:wq

With : all vi commands start, and wq is for write and quit.

Vi is a very old editor but it's present across all Unix and Linux distributions and it's a default editor used by many applications.

Contact About Us Support Network Servers Java Hosting Oxxus.net Order Now! Dedicated Servers VPS Hosting Tomcat Hosting Java Hosting Money Back Guarantee Privacy Policy Oxxus.net Terms of 
Service Contact About Us Servers Networks Support Domain Names SSL Certificates Java Wiki Tutorials E-learning 
Platforms