Interview Prep/Shell Scripting/cron and systemd timers

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, unless SHELL= is set.
  • PATH is minimal, typically /usr/bin:/bin.
  • No .bashrc or .profile, no aliases, no nvm/pyenv setup.
  • 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
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on cron and systemd timers