This repository contains practical Bash scripts I use (or would use) as a Linux system administrator and DevOps engineer. The focus is on small, readable scripts that automate routine tasks, but with professional‑grade enhancements such as logging, error handling, dry‑run modes, and security awareness.
- Monitoring & Alerts: Disk usage monitoring with configurable thresholds and optional email notifications.
- User Management Automation: Bulk user creation with password generation, group assignment, logging, and idempotency checks.
- Backup Automation: Timestamped, compressed backups with retention policies and disk space checks.
- Log Analysis: Nginx access log summaries including top IPs, URLs, status codes, user agents, request methods, and error rate calculation.
-
monitoring/disk-usage-alert.sh Checks disk usage on all mounted filesystems and prints warnings when usage exceeds a configurable threshold (default: 80%). Enhanced features: email alerts, hostname tagging, dry‑run mode.
-
user-management/bulk-user-create.sh Creates multiple Linux users from a text file. Supports username:group format, generates random passwords, logs actions, and skips existing users. Enhanced features: secure password handling, group assignment, dry‑run mode, error logging.
-
backups/enhanced-backup.sh Creates a timestamped compressed backup (tar.gz) of a source directory into a backup root directory. Enhanced features: disk space check, logging, retention policy (delete old backups), dry‑run mode.
-
utilities/nginx-log-summary.sh Generates a summary of an Nginx access log: top IPs, top URLs, HTTP status code distribution, request methods, user agents, and error rate calculation. Enhanced features: logging to file, dry‑run mode, error handling.
- Clone the repo to a Linux machine:
cd shell-scripting-for-sysadmins
-
Run any script with the required arguments. Examples: ./monitoring/disk-usage-alert.sh ./user-management/bulk-user-create.sh users.txt ./backups/enhanced-backup.sh /var/www /backups ./utilities/nginx-log-summary.sh /var/log/nginx/access.log
-
Optional: set environment variables for dry‑run mode or retention days:
DRYRUN=true ./backups/enhanced-backup.sh /var/www /backups RETENTION_DAYS=14 ./backups/enhanced-backup.sh /var/www /backups