User cron jobs

Users can also create their own cron jobs. This is done using the crontab utility (not to be confused with the /etc/crontab configuration file used for system cron jobs). The syntax of the crontab command is:

crontab [-u USER] [OPTIONS] [FILE]

If you don’t specify the user argument, the cron job will be associated with the current user.

 

To edit the user’s crontab file, open the crontab editor by running the crontab -e command. This will open up the file in the nano text editor:

crontab editor

The syntax of a cron job is similar to the one described in the previous lesson. You just don’t need to specify the account that will be used to execute the commands, since all commands will be run as the owner of the file. Consider the following line:

00 22 * * * rm /home/bob/trash/*

The line above specifies that the rm command will be run every day at 22:00.

To display the content of the user’s crontab file, use the -l option:

crontab l option

To remove the current crontab, use the crontab -r command.

You can also create a crontab file and pass it via the file parameter to the crontab utility.

 

The user crontab files are usually stored in the /var/spool/cron/ directory:

var spool cron crontabs

Note that you shouldn’t edit these file directly; use the crontab command instead.

Subscribe to our Newsletter

Like us on Facebook

top
Geek University 2019