Linux Sysadmin Test Prep

cron

cron


Tips

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`

Commands

CommandAction
crontab -lLists all the user's cron tasks
crontab -eEdit for current user (root if sudo)
crontab -e -u danielEdit for user daniel
crontab -rRemoves entry from spooler, but not crontab file

Troubleshooting

  • No environment variables! Use absolute paths!

  • ps ax | grep cron

  • start, restart, and check status of cron.service

  • * * * * * /bin/echo "cron works" >> /tmp/cronTest (User syntax doesn't have the User field, root does.)

  • Test script without cron.

  • Check permissions for script and any redirections.

  • Don't suppress output while debugging. 2>&1 to a file which you have write access instead of /dev/null. 2>&1 >> cron.out will append to user's home directory

  • grep cron /var/log/syslog

  • Add cron.crit /var/log/cron.log in /etc/rsyslog.d/50-default.conf and sudo /etc/init.d/rsyslog reload


Quiz

  • Run quiz with the argument cron This quiz matches strings instead of evaluating commands, so input must be entered without extra whitespace in the format specified by the question.
Edit this page on GitHub