Automating Server Administration with Bash Scripts ๐Ÿš€

Mihir SavlaMihir Savla
2 min read

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

0
Subscribe to my newsletter

Read articles from Mihir Savla directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mihir Savla
Mihir Savla