Bash Scripting and Automation
Objective: Write Bash scripts that automate repetitive system tasks.
If you're doing something more than twice, automate it. Scripting is what separates people who use computers from people who make computers work for them.
These programming fundamentals apply to Bash, Python, JavaScript, Go, and every other language you'll ever touch. Learn them once. Apply them everywhere.
Variables: Named containers that hold values. The name stays, the value can change.
Data types: Strings, integers, floats, booleans, lists.
Conditionals: If this, then do that. How programs make decisions.
Loops: Do something repeatedly. For each item in a list. While a condition is true.
Functions: Reusable blocks of code. Write once, call whenever you need it.
Input/Output: Reading data in (from a file, from a user), writing data out.
Error handling: Anticipate failures. Good code doesn't crash, it handles them.
Comments: The computer ignores them. Future-you needs them. Write them.
#!/bin/bashShebang. Tells the OS what interpreter to use.chmod +x script.shMake a script executableif [ condition ]; then ... fiConditional blockfor item in list; do ... doneFor loopwhile [ condition ]; do ... doneWhile loopfunction name() { ... }Define a reusable functioncommand > file.txtRedirect stdout to file (overwrite)command >> file.txtRedirect stdout (append)command1 | command2Pipe output to the next commandcrontab -eEdit your scheduled cron jobs
Write a Bash script that checks disk usage. If any partition is over 80% full, write a warning to /var/log/disk-warning.log with a timestamp.
Write a Bash script that backs up /opt/project to /tmp/backups/ with a timestamp in the filename (e.g., project-backup-2026-04-21.tar.gz).
Set up a cron job that runs your backup script every day at midnight.
Write a Bash script that accepts a username as an argument and outputs whether that user exists, what groups they belong to, and when they last logged in.
- bash-scripts/Subdirectory with all your scripts. Every script needs a comment block at the top: what it does, who wrote it, when. This is professional practice. Start now.
- programming-concepts.mdThe 8 fundamentals above, explained in your own words with examples from your own scripts.
- scripting-notes.mdConcepts learned, mistakes made, error messages and how you resolved them.
- cron-setup.mdYour crontab entries and how you verified they run on schedule.
- Get a Machine Running
- Know Your Hardware
- Learn to Talk to Your Machine
- Break It, Fix It
- Networking Fundamentals
- Users, Permissions, Security, and Remote Access
- Package Management
- Services and Self-Hosting
- Bash Scripting and Automation
- GitHub and Collaboration
- Python Programming
- Professional Communication
- Capstone Project