On a Schedule
Run scripts without being there, and make backups that work.
Updated
Scheduling
- Scheduled Jobs: 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.
- Scripts That Run Without You (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
- Backups That Work: 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
- Exercise: 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.