Linux - Shell script to monitor load on server, Server load monitoring
Shell script to monitor load on server
Shell script for load monitoring
The below script will help you to monitor the load on the serverSave the below code as load.sh
#!/bin/bash
echo Content-type: text/html
echo
echo "<html><title>Server Load Status</title>"
echo "<meta http-equiv="Refresh" content="60"></head>"
echo "<body><font size="1" face="Verdana"><b>"
echo "<table width="100%" border="1" cellpadding="1" cellspacing="1" align="center">"
echo "<tr>"
echo "<th>Server Name</th>"
echo "<th>IP</th>"
echo "<th>Uptime</th>"
echo "<th>Load</th>"
echo "<th>Service Scanned</th>"
echo "</tr>"
##copy load file into cgi-bin folder
##copy loadup.php into the server's default web data directory.
s24=$(GET http://ServerIP/loadup.php)
echo "<tr><td align="center">Domainname OR servername</td>"
echo "<td align="center">67.23.11.48</td>"
echo "<td align="center">"
echo $s24 | cut -d, -f1 | awk -F"up " '{ print $2 }'
echo "</td>"
echo "<td align="center">"
if [ `echo $s24 | awk -F": " '{ print$2 }' | cut -d. -f1` -ge 6 ]
then
echo "<font color=red>"
echo $s24 | awk -F": " '{ print$2 }'
echo "</font>"
else
echo $s24 | awk -F": " '{ print$2 }'
fi
echo "</td>"
echo "<td align="center">"
#http
if [ $(nmap -p 80 ServerIP | grep 80/ | awk '{ print$2 }') = "open" ]
then
echo "<font color=green>"
echo "Http"
echo "</font>"
else
echo "<font color=red>"
echo "Http"
echo "</font>"
fi
#smtp
if [ $(nmap -p 25 ServerIP | grep 25/ | awk '{ print$2 }') = "open" ]
then
echo "<font color=green>"
echo "Smtp"
echo "</font>"
else
echo "<font color=red>"
echo "Smtp"
echo "</font>"
fi
#mysql
if [ $(nmap -p 3306 ServerIP | grep 3306/ | awk '{ print$2 }') = "open" ]
then
echo "<font color=green>"
echo "MySQL"
echo "</font>"
else
echo "<font color=red>"
echo "MySQL"
echo "</font>"
fi
#ftp
if [ $(nmap -p 21 ServerIP | grep 21/ | awk '{ print$2 }') = "open" ]
then
echo "<font color=green>"
echo "Ftp"
echo "</font>"
else
echo "<font color=red>"
echo "Ftp"
echo "</font>"
fi
#https
if [ $(nmap -p 443 ServerIP | grep 443/ | awk '{ print$2 }') = "open" ]
then
echo "<font color=green>"
echo "Https"
echo "</font>"
else
echo "<font color=red>"
echo "Https"
echo "</font>"
fi
#imap
if [ $(nmap -p 110 ServerIP | grep 110/ | awk '{ print$2 }') = "open" ]
then
echo "<font color=green>"
echo "Pop"
echo "</font>"
else
echo "<font color=red>"
echo "Pop"
echo "</font>"
fi
save below code as loadup.php
#!/bin/bash echo Content-type: text/plain echo echo $(hostname) echo "=>" echo $(uptime)
Now execute the load.sh file. This shell script will print the load of your server.
The topic on Linux - Shell script to monitor load on server is posted by - Math
Hope you have enjoyed, Linux - Shell script to monitor load on serverThanks for your time