Scheduled tasks are known as cron jobs in Linux (though you could of course make use of the Gnome Scheduled Tasks tool if you would prefer) and are controlled by what are known as crontabs, basically simple text files containing a list of commands to be run at a specified time or interval. To add your own cron job is actually pretty simple.

The command:

crontab -e

…opens the crontab for the current user for editing purposes. Note that sudo crontab -e loads a different crontab from the one without sudo, one with more elevated rights of course.

Once the editor is open, you can specify a new cron job by adding a new line in the following format.

Crontabs are laid out in six distinct sections, namely minute (0-59), hour (0-23), day (1-31), month (1-12), weekday (0-6) and command. Sections are delimited by a space and sections 1 to 5 cannot have any spaces in it. Asterisks are wild cards and commas make up sets.

Thus for example we could add 01 04 1 1 1 /user/bin/somecommand, which would run /usr/bin/somecommand at 4:01am on January 1st plus every Monday in January.

It is suggested that you use full paths for the commands or scripts you want to execute.

Once you have added your new cron job lines, simple save the file and exit – the updated crontab will be immediately reloaded into memory.

And that is literally how easy it is to create a cron job!

Related Link: