Select your language

Cronjobs are used to automate recurring tasks. You can control the times and/or days on which certain programs or scripts are executed.

Create cronjob

To create a new cron job, log in to your Control Panel. You will find the Cronjob Manager on the server overview under «Advanced».

Notifications

If your cronjob generates text output when executed, this text will be sent to you by E-Mail.

You can specify a recipient address for the messages in the E-Mail address field. If you do not want these notifications, add the string >/dev/null 2>&1 at the end of your command to disable all output.

/usr/local/bin/php -f /home/username/bin/example.php >/dev/null 2>&1

or

/home/username/bin/example >/dev/null 2>&1

Cronjob command

The file you want to execute as a cronjob must either be executable or able to be executed by an interpreter.

Executable files

Binary programs or scripts with a shebang line can be executed directly.

Here you should make sure that the file mode allows this as well: The x-bit must be set. If you are unsure, set the mode to 755 or 750.

Shebang line

This special line in the script specifies the interpreter that can read and execute the contents of this script.

It is always the top line in the first column and it begins with the symbols #!, followed by the path to the interpreter.

A shebang line for a PHP script on our FreeBSD servers looks like this:

#!/usr/local/bin/php

Additional shebang lines:

#!/usr/local/bin/perl
#!/usr/local/bin/python

Starting scripts with an interpreter

To execute a script without a shebang line, you must invoke it with the appropriate interpreter.

Note that most additional programs running on FreeBSD Unix are found under /usr/local/bin/.

For information on this topic, refer to the article on paths, directories, system.

The cron command for a PHP script located in /home/username/bin/example.php looks like this:

/usr/local/bin/php -f /home/username/bin/example.php

Other command lines:

/usr/local/bin/perl /home/username/bin/example.pl
/usr/local/bin/python /home/username/bin/example.py

Time of execution

Five values have to be defined to determine the time of execution of a cronjob. Every minute, the cronjob daemon checks these values and will execute the cronjob when all five values are met.

Minute
Enter the minute in which you want your cronjob to be executed (0-59).
Hour
Enter the hour in which you want your cronjob to be executed (0-23).
Day
Enter the day of the month on which you want your cronjob to be executed (1-31).
Month
Enter the month of the year on which you want your cronjob to be executed (1-12).
Weekday
Enter the day of the week on which you want your cronjob to be executed (0-6, Sunday is 0 and 6 is Saturday).

List

You can also specify multiple comma-separated values. To start a job at xx:20 and xx:50, enter "20,50" for "Minute".

Wildcard

You can use a wildcard (*) for fields that you want to ignore. If, for example, you want to execute a job on every day of the year, you do not have to enter every possibility for «Day», «Month» and «Weekday». It is sufficient to complete these fields with an «*», which means “always true”.

Interval

If you want to execute a script at a specific interval, indicate this with "*/interval". The field is considered true if the current value is completely divisible by the interval. If you want a job to be executed every two hours, enter */2 for Hour. This will be true for 0, 2, 4, 6 o’clock, etc.

Examples

Executing at a specific time

To execute a script for a weekly summary every Saturday night at 23:15:

Minute: 15
Hour: 23
Day: *
Weekday: 6
Month: *

Command:

/home/username/bin/summary.pl

Execute every 5 minutes

You allow your website users to upload a picture of themselves to the website via E-Mail. For this purpose, you want to check this mailbox every five minutes for new pictures to add to the site.

Minute: */5
Hour: *
Day: *
Weekday: *
Month: *

Command:

/usr/local/bin/php -f /home/username/bin/checkmail.php

Repeated execution at night

To create a short movie, you want to download a nighttime picture of your city from a webcam at regular intervals. To do so, you have written a “one-liner” script that you want to execute every 20 minutes between the hours of 20:00 and 6:00 in the morning.

Minute: */20
Hour: 20-23,0-6
Day: *
Weekday: *
Month: *

Command:

/usr/local/bin/wget 'http://www.example.com/webcam.cgi?tilt=-20&yaw=93' -O /home/username/cam-images/`date +\%Y-\%m-\%d`.jpg

You can also periodically request a URL without downloading the file:

/usr/local/bin/wget -q -O /dev/null 'http://www.exmaple.com/cron.php' >/dev/null 2>&1

Additional resources

Additional information about working with cronjobs can be found here: http://www.howtoforge.de/anleitung/e...-in-cron-jobs/ or by referring to your preferred Unix guide.

Please use this form only to provide feedback on the above guide.
For support requests please use this form instead.

 

Unable to find what you were looking for?

Our support experts are happy to assist you personally!

 

© 2001 - Hostpoint AG