Linux Basic Commands
Cron jobs
Basic commands
SYNTAX
crontab [-u user] file
crontab [-u user] [-l | -r | -e] [-i] [-s]
List all crontabs:
# crontab -l
$ crontab -u root -l
Edit crontab
# crontab -e //edits crontab for user root
Removing all crontabs for specific user
# crontab -r //for root user
$ crontab -u root -r
Import crontab from file
$ crontab -u root /etc/crontab
Notice:
Commands crontab -e and crontab <file> creates new file. For example /var/spool/cron/root .
Crontab job example
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# Campaigns sender, runs each minute.
* * * * * /usr/bin/php -q /homemiko/info_mikosoft/mej/public_html/apps/console/console.php send-campaigns >/dev/null 2>&1
# Transactional email sender, runs once at 2 minutes.
*/2 * * * * /usr/bin/php -q /homemiko/info_mikosoft/mej/public_html/apps/console/console.php send-transactional-emails >/dev/null 2>&1
# Bounce handler, runs once at 10 minutes.
*/10 * * * * /usr/bin/php -q /homemiko/info_mikosoft/mej/public_html/apps/console/console.php bounce-handler >/dev/null 2>&1
# Feedback loop handler, runs once at 20 minutes.
*/20 * * * * /usr/bin/php -q /homemiko/info_mikosoft/mej/public_html/apps/console/console.php feedback-loop-handler >/dev/null 2>&1
# Delivery/Bounce processor, runs once at 3 minutes.
*/3 * * * * /usr/bin/php -q /homemiko/info_mikosoft/mej/public_html/apps/console/console.php process-delivery-and-bounce-log >/dev/null 2>&1
# Daily cleaner, runs once a day.
0 0 * * * /usr/bin/php -q /homemiko/info_mikosoft/mej/public_html/apps/console/console.php daily >/dev/null 2>&1
Controlling cron service
Centos 6.6 ------> # service crond start | restart | stop | status
Ubuntu 12.04 --------> # service cron start | restart | stop | status