cornerhost wiki   FAQ/cron UserPreferences
 
HelpContents FindPage Diffs Info Edit Subscribe XML Print View

  1. basic cron information
  2. How do I setup a cron job?
  3. How do I setup a cron job? (long version)
  4. How do I know it worked?
  5. My cron job does not run, what's wrong?
  6. What user does the cron job run under?
  7. Turn off cron job email notifications

basic cron information

Cron jobs allow you to run programs on a recurring schedule.

How do I setup a cron job?

Here is the short version, for those in a hurry...

How do I setup a cron job? (long version)

There are several ways to upload files to the server, including FTP, and scp. Check out other FAQ on these topics for more information. If you have a shell account, you can edit a file on the server using vi or emacs.

You have to give the file execute permissions for your account. A "700" permission is sufficient which gives you rights to read/write/execute, but no one else can read/write/execute your file. Some FTP programs allow you to set the permissions on the file, or if you have shell access, the "chmod" command (run "man chmod" for more information) allows you to change the permissions of a file.

You can login to the cornerhost control panel from the www.cornerhost.com home page.

Adding crontab lines are complicated, and better documented elsewhere. For beginners you may want to use the following template:

15 4 * * *  nice $HOME/run_every_day_at_four_fifteen_am.py

The "15 4 * * *" is the time of day to run the program everyday (i.e. 4:15, military time). Other times are:

In general, the program you run should be: "nice $HOME/programname". Replace "programname" with the file you want to run. The "nice" command lets the server know that the running program is not time sensitive and should yield to time sensitive processes, such as your website. The "$HOME" is a special keyword that is the path to your home directory. The following is the equivalent command without the $HOME keyword, "15 4 * * * nice /home/clay/run_every_day_at_four_fifteen_am.py".

You can also run programs within a directory in your home directory:

15 4 * * *  nice $HOME/myscripts/run_every_day_at_four_fifteen_am.py

A word of warning: The last line must have a <return> at the end, otherwise your cron job will be ignored.

How do I know it worked?

You will receive an email as soon as the file is finished running.

My cron job does not run, what's wrong?

Double check that the last line has a return at the end.

What user does the cron job run under?

:) No, it does not run under the root account. It runs under your account, which means your account must have execute permissions on the file, and the program or script can only do what your account is allowed to do.

Turn off cron job email notifications

Redirect the output of the command to /dev/null. If there's no output, cron won't send you an email.

Example:

00 * * * * $HOME/hourly.py > /dev/null

For complete silence:

00 * * * * $HOME/hourly.py > /dev/null 2>&1


PythonPowered