What is different about the environment a cron job runs in?
BeginnerConceptcron and systemd timers
Answer
- Shell is
/bin/sh(dash on Debian/Ubuntu), not Bash, unlessSHELL=is set. PATHis minimal, typically/usr/bin:/bin.- No
.bashrcor.profile, no aliases, nonvm/pyenvsetup. - Working directory is the user's home.
- No terminal; output is mailed to
MAILTO(or lost if no MTA). %is converted to a newline unless escaped as\%.
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
[email protected]
0 3 * * * /opt/scripts/backup.sh >> /var/log/backup.log 2>&1
More on cron and systemd timers
Explain the five cron time fields with examples.BeginnerWhat is the difference between a user crontab, `/etc/crontab`, `/etc/cron.d/` and `/etc/cron.daily/`?IntermediateHow do you prevent overlapping cron runs and capture output properly?IntermediateWhat is a systemd timer and how does it compare to cron?IntermediateWrite a minimal systemd service and timer that run a backup at 02:30 daily.IntermediateWhat is the difference between `OnCalendar=`, `OnBootSec=` and `OnUnitActiveSec=`?Advanced