Skip to content

Linux & shell: Scheduling: cron & systemd timers

6 Linux & shell commands: Scheduling: cron & systemd timers. Click a command to see what each part does.

Index
6 items
Click a command to see what each part does.

Scheduling: cron & systemd timers6

  • crontab -l; crontab -eList and edit your cron jobs

    What each part does

    1. crontab -lshow your user's cron jobs (sudo crontab -l -u <user> for others)
    2. crontab -eedit them in $EDITOR
  • */5 * * * * /usr/local/bin/<script> >> /var/log/<script>.log 2>&1Cron line format

    What each part does

    1. */5 * * * *minute hour day-of-month month day-of-week: here every 5 minutes
    2. /usr/local/bin/<script>use full paths: cron has a minimal PATH
    3. >> <log> 2>&1append output and errors to a log, otherwise they are mailed or lost
  • ls /etc/cron.d /etc/cron.daily /etc/cron.hourly; cat /etc/crontabSystem-wide cron jobs

    What each part does

    1. /etc/cron.djob files from packages and admins (with a user field)
    2. /etc/cron.daily, hourly...scripts run by run-parts at those intervals
  • journalctl -u cron -u crond --since todayDid cron run my job?

    What each part does

    1. journalctl -u cron -u crondcron daemon logs (cron on Debian, crond on RHEL); or grep CRON /var/log/syslog
    2. --since todayonly today
  • systemctl list-timers --allList systemd timers and when they run next

    What each part does

    1. list-timersevery timer: next run, last run, the unit it starts
    2. --allinclude inactive timers
  • echo '<command>' | at 02:00Run a command once at a later time

    What each part does

    1. at 02:00run once at 2 AM (also: at now + 30 minutes); atq lists, atrm removes

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…