🪟 Windows TippsModify Windows Support Phone Number with PowerShell(03.09.2026 um 00:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🪟 Windows TippsMicrosoft bringt Emoji 17.0 auf Windows 11(31.08.2026 um 08:16 Uhr)
🪟 Windows TippsModify Windows Support Phone Number with PowerShell(03.09.2026 um 00:00 Uhr)
🔧 AI Nachrichten Podcast: ChatGPT schwatzt Nutzern in Deutschland jetzt Werbung auf(28.08.2026 um 08:46 Uhr)
🪟 Windows TippsMicrosoft bringt Emoji 17.0 auf Windows 11(31.08.2026 um 08:16 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 3 Min Lesezeit
0

Comprehensive Bash System Monitoring Script: Technical Breakdown

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

In today's fast-paced IT environments, keeping track of system performance is crucial. This bash script provides an elegant, automated solution for monitoring critical system metrics and sending timely alerts when resources are under strain.






Understanding the Script's Architecture



The script is designed to monitor three primary system health indicators:




  • CPU Usage

  • Memory Consumption

  • Disk Space Utilization






Key Functionalities






Logging Mechanism



The script includes a robust logging function that timestamps every event. All system metrics and alerts are recorded in /var/log/sysmonitor.log, providing a comprehensive audit trail for system administrators.




CODE
logfile=/var/log/sysmonitor.log

log(){
local message=$1
echo "$message - $(date +%T)" >> $logfile
}
# Logging function with timestamp
# Uses local variable for message
# Appends to log file with current time










Metric Collection



Each metric collection function leverages standard Linux command-line tools:



top for CPU usage

free **for memory consumption

**df
for disk space utilization



CPU Usage Metrics




CODE
CPU_metrics(){    
local cpu_usage=$(top -bn1 | grep "CPU(s)" | awk '{print $1 + $2 + $3}')
echo "$cpu_usage"
log "Cpu usage is $cpu_usage"
}

# Uses `top` command to retrieve CPU usage
# Adds first three CPU percentage columns
# Logs the result






Memory Usage Metrics




CODE
Memory_metrics(){     
local Mem_usage=$(free -m | awk '/Mem:/ {print ($3 / $2) * 100.00}')
echo "$Mem_usage"
log "Cpu usage is $Mem_usage"
}
# Uses `free` command to calculate memory usage
# Calculates percentage of used memory
# Converts to percentage with decimal precision







Disk Usage Metrics




CODE
disk_usage_metrics(){     
local disk_usage=$(df -h --total | grep ^total | awk '{print $5}' | sed 's/%//')
echo "$disk_usage"
log "Disk Usage is $disk_usage"
}
# Uses `df` command to get total disk usage
# Removes percentage symbol for calculation






Metric Processing




CODE
dskusage=$(printf "%.0f" "$(disk_usage_metrics)")
memusage=$(printf "%.0f" "$(Memory_metrics)")
cpuUsage=$(printf "%.0f" "$(CPU_metrics)")
# Converts floating-point metrics to integers
# Uses printf to round to nearest whole number









Threshold-Based Alerting



The script defines critical thresholds for each metric:




  • Disk Usage: 75%

  • Memory Usage: 85%

  • CPU Usage: 90%



When any metric exceeds its predefined threshold, the script:



Logs the event in the system log

Sends an email alert to the specified address




CODE
CPU_threshold=90
Mem_threshold=85
Disk_threshold=75

if [ "$dskusage" -gt "$Disk_threshold" ] then
echo "Disk limt exceeded!!!" 1>>$logfile
mail -s "Disk Limit Alert" [email protected] <<< "Disk usage has exceeded Limit. Kindly review"
fi
# Checks if disk usage exceeds 75%
# Logs the event
# Sends email alert
# Similar logic for memory and CPU thresholds










Performance Automation



The script is scheduled using a crontab entry to run every 4 hours, ensuring continuous, hands-off system monitoring.




CODE
cron_job="0 */4 * * */workspace/Automated-System-Monitoring-/Monitor.sh 1>>$logfile"
(crontab -l | grep -v -F "$cron_job"; echo "$cron_job") | crontab -
# Schedules script to run every 4 hours
# Adds to crontab without duplicating existing entries









Implementation Tips



To use this script:



Replace

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Modify Windows Support Phone Number with PowerShell
1 Quelle
Die Zukunft des Einkaufens: Warum wir ein neues Kapitel aufschlagen (und wie du es mitschreiben kannst)
1 Quelle
ZDE Podcast 251: Wie sieht digitales Instore Marketing 2026 aus, Amit Chatterjee?
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Comprehensive Bash System Monitoring Script: Technical Breakdown

Thematisch verwandte Begriffe: Comprehensive, Bash, System, Monitoring · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...