Crontab overview

Overview

The crontab command, found in Unix and Unix-like operating systems, is used to schedule commands to be executed periodically.

Generally, crontab uses a daemon, crond, which runs constantly in the background and checks once a minute to see if any of the scheduled jobs need to be executed. These jobs are generally referred to as cron jobs. Cron jobs run as the user who creates them, as though that user typed the command into their shell.

Only shell users can create cron jobs. For help setting up a shell user, see the Creating a user with Shell (SSH) access article.

Crontab file contents on the server

Due to the complex nature of translating user supplied content from the panel to the server, what you enter in to the panel is not what you see in the crontab file. The following example is a more complex cron job using a wget command.

crontab.png

The crontab file on the server then appears as follows:

###--- BEGIN DREAMHOST BLOCK
###--- Changes made to this part of the file WILL be destroyed!
# testing a cron
MAILTO="user@example.com"
@hourly /usr/local/bin/setlock -n /tmp/cronlock.3788814087.215158 sh -c $'/usr/local/php71/bin/php /home/example_username/mail.php'
###--- You can make changes below the next line and they will be preserved!
###--- END DREAMHOST BLOCK

When the 'Use locking' option is selected, the command(s) you want executed are filtered through a unique invocation of the setlock command.

View the setlock man page for further information. The use of setlock results in error messages if your cron job is invoked before the last iteration of the job releases your unique lockfile. This can happen if your script takes more time to run than the time between job executions.

See also

Did this article answer your questions?

Article last updated PST.