Cron Peek

View saved

What cron does

Cron runs commands on a schedule. Your Bash script can be the command—if it uses absolute paths and a clean environment.

Crontab fields

Minute, hour, day of month, month, day of week, then the command.

# m h dom mon dow command
0 7 * * * /home/ada/bin/backup.sh

Environment gotchas

  • PATH is minimal—use full paths to binaries
  • Working directory may not be your home project folder
  • Output is often emailed or discarded—log to a file
  • Test the exact command manually first

Log from the script

Write simple logs so failures are visible.

log="/var/log/backup.log"
{
  date -Is
  /home/ada/bin/backup.sh
} >>"$log" 2>&1

Comments

One comment per signed-in account. Comments are saved with this page’s URL.