Chapter 10 of 10All chapters
Chapter 10 of 10
Scripts
Saving a job so it runs again.
A first script
A file starting with #!/bin/bash, made executable with chmod +x, runs as a command. Variables, if statements and for loops turn a sequence of commands into a tool.
- set -euo pipefail at the top makes a script stop on the first error rather than continuing.
- Quote your variables. Unquoted paths with spaces cause most script bugs.
Scheduling
cron runs a command on a schedule and systemd timers do the same with better logging. Both are how backups and cleanups happen without anyone remembering.