# On a Schedule

Run scripts without being there, and make backups that work.

Updated: November 10, 2026

## [Scheduling](https://www.ask-codey.com/courses/bash-in-depth/topics/bash-scheduling)

1. [Scheduled Jobs: cron](https://www.ask-codey.com/lessons/bash-cron) (Journeyman): cron runs commands at the times you set, even when you aren't at the keyboard: each line of your crontab has five time fields, minute, hour, day of the month, month and day of the week, then the command; crontab -e edits it, crontab -l shows it, and a job's output goes into a log file you name.
2. [Scripts That Run Without You](https://www.ask-codey.com/lessons/bash-unattended-scripts) (Freelancer): cron runs a script from your home folder, with a short PATH, no terminal and no keyboard, so a script that works when you type it can fail at 18:00; give it full paths and a PATH of its own, write everything to a log with the date and time, never ask a question, and take a lock with flock so two copies never run at once.

## [Backups](https://www.ask-codey.com/courses/bash-in-depth/topics/bash-backups)

1. [Backups That Work: rsync](https://www.ask-codey.com/lessons/bash-rsync) (Journeyman): rsync -a copies a folder and, every time after the first, only the files that changed; a slash at the end of the source means "what's inside"; --delete makes the backup a mirror, so rehearse it with -n first; and a backup counts only once you've restored from it and compared the result with diff -r.

## [Exercise: Back Up While You Sleep](https://www.ask-codey.com/courses/bash-in-depth/topics/exercise-bash-back-up-while-you-sleep)

1. [Exercise: Back Up While You Sleep](https://www.ask-codey.com/lessons/exercise-bash-back-up-while-you-sleep) (Journeyman): Finish a nightly backup that cron can run while nobody is there: rsync mirrors a school-work folder, the script works from any folder with a PATH of its own, logs everything with the date and time, takes a lock with flock, refuses to mirror an empty folder and can rehearse with --dry-run; then write its crontab line for 18:00, while a check runs it the way cron would.

Source: https://www.ask-codey.com/courses/bash-in-depth/chapters/bash-on-a-schedule
