Automating Server Administration with Bash Scripts π
Managing Linux servers often means running repetitive commands to check disk space, analyze email logs, or review cron jobs.
I wanted to make this faster and easier β so I created three Bash scripts that can do these tasks in seconds.
These scripts are built for CentOS, AlmaLinux, and similar distributions.
You can find the complete source code here:
π View on GitHub
π The Three Scripts
1οΈβ£ diskreport.sh
Displays disk usage statistics in a clean, color-coded format.
Helps identify partitions running out of space before they become a problem.
2οΈβ£ emailreport.sh
Analyzes Exim email logs for a time range you specify.
Shows:
Total sent emails
Bounce count
Top senders & recipients
Per-user email volume (for cPanel servers)
3οΈβ£ cronreport.sh
Lists all cron jobs on the server.
Shows when they last ran, execution duration, and flags suspicious entries for review.
π How to Run the Scripts
Run Locally
chmod +x scriptname.sh
sudo ./scriptname.sh
Or:
sudo bash scriptname.sh
Run Without Saving (wget)
You can execute the script directly without saving it permanently:
sudo bash <(wget -qO- http://your-server-ip/scriptname.sh)
π Create a Systemd Service (Optional)
Want the script to run automatically or be easily triggered? You can create a systemd service.
Basic Steps:
1οΈβ£ Place your script in /usr/local/bin/
This ensures it can be run from anywhere without specifying the full path.
2οΈβ£ Create a service file
sudo nano /etc/systemd/system/myscript.service
Paste:
[Unit]
Description=My Custom Script Service
[Service]
Type=simple
ExecStart=/usr/local/bin/myscript.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
3οΈβ£ Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable myscript.service
sudo systemctl start myscript.service
π Why I Built These
I work on servers where I need quick insights β whether itβs disk space, email health, or cron job activity.
Instead of manually checking multiple commands and logs, these scripts provide one-command reports that are easy to read and act on.
π Get the Scripts
You can download all three scripts from my GitHub repository:
π GitHub: Server Administration Bash Scripts
If youβre into Linux server administration, DevOps, or automation, letβs connect:
π LinkedIn β Mihir Savla