Difference between revisions of "Cron entry"
(Created a howto for cron)
Revision as of 11:48, 8 July 2011
How to automatically run a command periodically with Cron daemon.
This is the preferred method on SME Server, see documentation. Custom templates survive updates and are included in a regular backup.
Make directory for custom template
mkdir -p /etc/e-smith/templates-custom/etc/crontab
Create and open a file with the text editor nano:
Add your cron entries, example for running a script daily at 16,00:
# Run custom script with cron 00 16 * * * root /root/cronjobs/external_ip.sh
Syntax: (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) (user) (command)
Save and exit.
Regenerate the template:
Verify your new entry in the regenerated crontab:
Restart the cron daemon:
service crond restart
This method is simple, but will not be included in a regular backup and might have problems with updates and upgrades.
There are four directorys in /etc/: cron.hourly, cron.daily, cron.weekly and cron.monthly.
Any executable script dropped in these will be executed automatically each period (indicated by the directory name).
Cron jobs are executed by the user admin (which is an alias for root).
Cron job results are usually sent by email to the administrator.
A script fired by a cron entry must be executable.