Real-Time Corporate Shell Scripts

π 10 Real-Time Corporate Shell Scripts Every DevOps & SysAdmin Should Know
Shell scripting remains one of the most powerful skills for DevOps engineers, system administrators, and cloud professionals. Whether you're managing servers, automating daily tasks, or improving system reliabilityβshell scripts make your life easier.
In this blog, Iβll share 10 real-time corporate production-ready shell scripts, along with complete explanations. These scripts are practical, commonly used in companies, and easy to adapt to your own infrastructure.
Letβs dive in! β‘
ποΈ 1. Backup Automation Script
π Script
#!/bin/bash
SOURCE="/home/ubuntu/aditya"
DESTINATION="/home/ubuntu/jaiswal/"
DATE=$(date +%Y-%m-%d_%H-%M-%S)
mkdir -p $DESTINATION/$DATE
cp -r $SOURCE $DESTINATION/$DATE
echo "Backup completed on $DATE"
π§ Explanation
SOURCE: Directory to backupDESTINATION: Storage locationDATE: Timestamp for versioningmkdir -p: Creates directory if missingcp -r: Copies files recursively
β±οΈ Automate with Cron
* * * * * /path/to/backup.sh
(Runs every minute β adjust as needed)
π½ 2. Disk Usage Monitoring Script
π Script
#!/bin/bash
THRESHOLD=80
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' |
while read output; do
usage=$(echo $output | awk '{ print $1}' | cut -d'%' -f1)
partition=$(echo $output | awk '{ print $2 }')
if [ $usage -ge $THRESHOLD ]; then
echo "Warning: Disk usage on $partition is at ${usage}%"
fi
done
π§ Why This Is Useful
Helps avoid disk-full outages
Notifies when usage > 80%
Ideal for cron-based server health checks
π οΈ 3. Service Health Check (Auto Restart)
π Script
#!/bin/bash
SERVICE="nginx"
if systemctl is-active --quiet $SERVICE; then
echo "$SERVICE is running"
else
echo "$SERVICE is not running"
systemctl start $SERVICE
fi
π§ Explanation
Checks service status
Automatically restarts if not running
Useful for nginx, mysql, apache, etc.
Helps keep production uptime high
π 4. Network Connectivity Test
π Script
#!/bin/bash
HOST="google.com"
OUTPUT_FILE="/home/ubuntu/output.txt"
if ping -c 1 $HOST &> /dev/null; then
echo "$HOST is reachable" >> $OUTPUT_FILE
else
echo "$HOST is not reachable" >> $OUTPUT_FILE
fi
π§ Use Case
Logs connectivity issues
Good for debugging networking or internet outages
π’οΈ 5. MySQL Database Backup Script
π Script
#!/bin/bash
DB_NAME="mydatabase"
BACKUP_DIR="/path/to/backup"
DATE=$(date +%Y-%m-%d_%H-%M-%S)
mysqldump -u root -p $DB_NAME > $BACKUP_DIR/$DB_NAME-$DATE.sql
echo "Database backup completed: $BACKUP_DIR/$DB_NAME-$DATE.sql"
π§ Why It's Important
Creates timestamped database backups
Works across MySQL-based servers
Ideal for daily cron backups
β±οΈ 6. System Uptime Script
π Script
#!/bin/bash
uptime -p
π§ What It Does
Shows how long server has been running
Helps monitor reboots, downtime
π‘ 7. Active Listening Ports Checker
π Script
#!/bin/bash
netstat -tuln | grep LISTEN
π§ Usage
Lists active services and ports
Important for troubleshooting networking issues, traffic, open ports
β»οΈ 8. Automatic System Update Script
π Script
#!/bin/bash
apt-get update && apt-get upgrade -y && apt-get autoremove -y && apt-get clean
echo "System packages updated and cleaned up"
π§ What It Does
Updates server
Removes unused packages
Keeps system optimized and secure
π 9. HTTP Response Time Checker
π Script
#!/bin/bash
URLS=("https://www.devopsshack.com/" "https://www.linkedin.com/")
for URL in "${URLS[@]}"; do
RESPONSE_TIME=$(curl -o /dev/null -s -w '%{time_total}\n' $URL)
echo "Response time for $URL: $RESPONSE_TIME seconds"
done
π§ Use Cases
Monitor website performance
Detect slow or down services
Ideal for DevOps monitoring pipelines
π§ 10. Top Memory-Consuming Processes
π Script
#!/bin/bash
ps aux --sort=-%mem | head -n 10
π§ Why This Helps
Identifies heavy processes
Useful for fixing performance bottlenecks
Often used during server audits
π― Final Thoughts
These 10 real-time scripts are practical, production-ready, and commonly used in DevOps, SRE, and system administration roles. Whether youβre:
β Automating backups
β Monitoring system health
β Debugging performance
β Optimizing server security


