Operations 3 min read

280 Essential Shell Scripts Every Sysadmin Should Use

This article introduces three practical Shell scripts—an alert sender for Linux systems, a MySQL backup loop, and a real‑time network interface traffic monitor—demonstrating how automation can streamline routine operations and improve system reliability.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
280 Essential Shell Scripts Every Sysadmin Should Use

Shell scripting is a powerful language for automating commands in Linux, enabling batch file processing, tool development, and more.

Below are three practical scripts frequently used by operations engineers.

1. Linux System Alert Script

# yum install mailx
# vi /etc/mail.rc
set [email protected] smtp=smtp.163.com
set [email protected] smtp-auth-password=123456
set smtp-auth=login

2. MySQL Database Backup Loop

#!/bin/bash
DATE=$(date +%F_%H-%M-%S)
HOST=localhost
USER=backup
PASS=123.com
BACKUP_DIR=/data/db_backup
DB_LIST=$(mysql -h $HOST -u $USER -p$PASS -s -e "show databases;" 2>/dev/null | egrep -v "Database|information_schema|mysql|performance_schema|sys")
for DB in $DB_LIST; do
  BACKUP_NAME=$BACKUP_DIR/${DB}_${DATE}.sql
  if ! mysqldump -h $HOST -u $USER -p$PASS -B $DB > $BACKUP_NAME 2>/dev/null; then
    echo "$BACKUP_NAME backup failed!"
  fi
done

3. Real‑time Network Interface Traffic Monitor

#!/bin/bash
NIC=$1
echo -e " In ------ Out"
while true; do
  OLD_IN=$(awk '$0~"'$NIC'"{print $2}' /proc/net/dev)
  OLD_OUT=$(awk '$0~"'$NIC'"{print $10}' /proc/net/dev)
  sleep 1
  NEW_IN=$(awk '$0~"'$NIC'"{print $2}' /proc/net/dev)
  NEW_OUT=$(awk '$0~"'$NIC'"{print $10}' /proc/net/dev)
  IN=$(printf "%.1f%s" "$((($NEW_IN-$OLD_IN)/1024))" "KB/s")
  OUT=$(printf "%.1f%s" "$((($NEW_OUT-$OLD_OUT)/1024))" "KB/s")
  echo "$IN $OUT"
  sleep 1
done
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SysadminNetwork Monitoringmysql backup
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.