Low Orbit Flux Logo 2 F

Linux Command - crontab

The Linux crontab command is used to manage jobs in the crontab.

The crontab ( cron table ) is a list of jobs that are run on a set schedule. These are generally defined in crontab files for each user.

View crontab entries for the current user:

crontab -l

Edit crontab entries for the current user:

crontab -e

Remove crontab for current user:

crontab -r crontab -ri # prompt first

View the root crontab and entries for other users:

sudo su - crontab -l # view root crontab crontab -u user1 -l # view other users crontab crontab -u user2 -l # view other users crontab crontab -u user3 -e # view other users crontab

A crontab entry looks like this:

30 08 10 06 * /opt/myserver/test1.sh

These are the fields:

minute hour day of month month day of week command

Use an * as the wild card. For example run a job every minute, all the time:

Using ranges:

00 09-17 * * 1-5 /opt/myserver/test1.sh

Every 10 minutes:

*/10 * * * * /opt/myserver/test1.sh

Run command yearly:

@yearly /opt/myserver/test1.sh

Run command on reboot:

@reboot /opt/myserver/test1.sh

Keywords:

@yearly 0 0 1 1 *
@daily 0 0 * * *
@hourly 0 * * * *
@reboot at startup

Replaced current crontab with the contents of a specific file ( will also over write exiting file ):

crontab /home/user1/test.txt

Common file locations:

/var/spool/cron/crontabs/user1 a users crontab
/etc/crontab root crontab
/etc/cron.allow if file exists, user must be listed here to use crontab command
/etc/cron.deny if allow file doesn’t exist, user must not be listed here to use crontab command