Schedule reoccurring jobs using CRONTAB in Linux

Home > Search

Creating a crontab job

The crontab command with the -e (edit) option can be used to edit the cron table. Each user has their own cron table. Editing the cron table as root will edit root's cron table. 

[root@server1 ~]# crontab -e


Editing the cron table as John.Doe will edit John's cron table.

[JohnDoe@server1 ~]# crontab -e


If a non-root user has permission to use sudo, using sudo will run the script as root.

[JohnDoe@server1 ~]# sudo crontab -e


Hourly, Daily, Weekly, Monthly, Reboot

The @ symbol can be used to run a command or script once every hour, once every day, once every week, once every month, or when the server is restarted.

@hourly  bash /home/JohnDoe/scripts/
@daily   bash /home/JohnDoe/scripts/
@weekly  bash /home/JohnDoe/scripts/
@monthly bash /home/JohnDoe/scripts/
@reboot  bash /home/JohnDoe/scripts/


The sleep option can be used to wait a while before running a script after reboot. In this example, is run 1 minute after reboot.

@reboot sleep 60 && bash /home/JohnDoe/scripts/


Specific date time

You can specify an exact date and time to run a command or script. The syntax of the lines in the cron table is: <minute> <hour> <day of the month> <month> <day of the week> <command or script to execute>. For example, to run every day at 1:00 am:

0 1 * * * bash /home/JohnDoe/scripts/


Or, to remove every file in the /tmp directory every day at 1:00 am.

0 1 * * * /bin/rm /tmp/*


The first 5 fields of crontab are:

  • minute (0-59)
  • hour (0-23)
  • day of the month (1-31)
  • month (1-12)
  • day of the week (0-7)
    • 0 = Sunday
    • 1 = Monday
    • 2 = Tuesday
    • 3 = Wednesday
    • 4 = Thursday
    • 5 = Friday
    • 6 = Saturday
    • 7 = Sunday



Each field can accept a range. For example, to run at 1:00 am, Monday through Friday:

0 1 * * 1-5 bash /etc/cron.daily/


Comma separated lists

Fields can also accept a comma separated list. For example, to run at 1:00 am on Saturday and Sunday:

0 1 * * 6,7 bash /etc/cron.daily/


Once every minute

All astericks can be used to run a cron job once every minute.

* * * * * bash /etc/cron.daily/


Viewing the cron table

The crontab -l (list) command can be used to view the entries in crontab.

~]# crontab -l
0 1 * * * bash /etc/cron.daily/


Likewise, the /var/spool/cron/crontab/username file can be viewed to view each users cron table.

~]# cat /var/spool/cron/crontab/root
0 1 * * * bash /etc/cron.daily/


Removing cron tables

The crontab -r (remove) command can be used to remove a users entire cron table. For example, to remove user1 cron table:

~]# crontab -r


Cron log

The cron log is typically located at /var/log/cron.

~]# tail /var/log/cron


The syslog or rsyslog daemon control how events are logged to /var/log/cron. If you want to change logging, such as disabling logging, you'll edit the syslog or rsyslog configuration file and then restart the syslog or rsyslog daemon.

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter in the box below so that we can be sure you are a human.