Introduction
Sysadmin scripts help save time and reduce mistakes by doing routine tasks automatically.
Sysadmin scripts help save time and reduce mistakes by doing routine tasks automatically.
#!/bin/bash # Commands to automate tasks command1 command2 ...
#!/bin/bash to tell the system to use bash.#!/bin/bash echo "Backing up files..." cp -r /home/user/data /backup/data
#!/bin/bash if systemctl status apache2 | grep 'active (running)'; then echo "Apache is running" else systemctl start apache2 echo "Apache started" fi
This script checks the disk space used on the root partition. If usage is above 80%, it shows a warning.
#!/bin/bash # Simple script to check disk space and alert if low THRESHOLD=80 USAGE=$(df / | tail -1 | awk '{print $5}' | sed 's/%//') if [ "$USAGE" -gt "$THRESHOLD" ]; then echo "Warning: Disk usage is above $THRESHOLD%" else echo "Disk usage is normal" fi
Automating tasks reduces human errors and frees up time for more important work.
Always test scripts carefully before running them on important systems.
Sysadmin scripts automate repetitive tasks to save time.
They help keep systems running smoothly without manual work.
Simple bash scripts can check, backup, and fix common issues automatically.
#!/bin/bash tells the system to use bash to run the script.#!/bin/bash
count=0
for file in /tmp/*; do
if [ -f "$file" ]; then
((count++))
fi
done
echo $count#!/bin/bash file="/etc/passwd" cp $file /backup/ if [ $? -eq 0 ]; then echo "Backup successful" else echo "Backup failed" fi
Pass the test and this pattern moves unknown