Skip to content

Instantly share code, notes, and snippets.

@kzltp
Last active May 31, 2020 21:09
Show Gist options
  • Select an option

  • Save kzltp/737122a90ca22ae29d87 to your computer and use it in GitHub Desktop.

Select an option

Save kzltp/737122a90ca22ae29d87 to your computer and use it in GitHub Desktop.
This article we are introducing a shell script to perform linux system health check. This script collects system information and status like cpu / memory / disk usage.
#!/bin/bash
MAİL="mail@mail.com"
# Memory
free -m | awk 'NR==2{printf $3}' > /tmp/memory
if [[ $(free -m | awk 'NR==2{printf $3}') -gt 3600 ]];
then
/bin/mail -s "Memory Usage" $MAİL < /tmp/memory
else
exit
fi
#Disk
df | awk 'NR==2{printf $4 }' > /tmp/disk
if [[ $(df | awk 'NR==2{printf $4 }') -lt 10000 ]];
then
/bin/mail -s "Disk Usage" $MAİL < /tmp/disk
else
exit
fi
#CPU
mpstat 1 1 | awk 'NR==4{printf int($4) }' > /tmp/cpu
if [[ $(mpstat 1 1 | awk 'NR==4{printf int($4) }' ) -gt 50 ]];
then
sleep 60
if [[ $(mpstat 1 1 | awk 'NR==4{printf int($4) }' ) -gt 50 ]];
then
/bin/mail -s "CPU Usage" $MAİL < /tmp/cpu
else
exit
fi
else
echo " CPU " > /tmp/echo
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment