Quick Server Health Check On Login Using Bash Profile

I strive in being a proactive sysadmin/dba/app admin so I use a few methods to provide me critical data. For this post I’m going to cover the use of the .bash_profile and show how we can combine some commands to provide visual output so we can assess the server health each time you login.

I always take a backup of files before performing manipulation, so lets do that here. Preserve permissions where possible.

-bash-3.2$ cp -rp ~/.bash_profile ~/.bash_profile_12022015

What I am interested in capturing here is some quick information, so we’ll grab the hostname, load, disk usage and the last reboot.

Breaking it down….hostname, load and last reboot

echo -e "Name: `hostname -s` | Rebooted: `who -b | awk '{print $3,$4}'` | Load: `uptime |awk '{print $10, $11, $12}'`\n"

Next we’ll add some code to check disk information, print and display it so it is easily

df -Pkh | grep -v 'Filesystem' |egrep -vi 'home|dev/shm' > /tmp/disk.status
while read DISK
LINE=`echo $DISK | awk '{print $6," --> \t",$5," used"}'`
USAGE=`echo $DISK | awk '{print $5}' | cut -f1 -d%`
if [ $USAGE -ge 95 ]
 elif [ $USAGE -ge 90 ]
echo -e $STATUS -- $LINE "\t\t\n"
done < /tmp/disk.status
echo ""
rm -rf /tmp/disk.status

Lets test it out

-bash-4.1$ ssh mwlab01-vm02
Last login: Wed Dec 2 09:52:32 2015 from
Name: mwlab01-vm02 | Rebooted: 2015-10-29 14:41 | Load: 2.57, 2.58, 2.50
NORMAL -- / --> 22% used
NORMAL -- /boot --> 20% used
NORMAL -- /opt/mwlab01_scripts --> 25% used
CAUTION -- /opt/mwlab01_backup --> 81% used
NORMAL -- /opt/mwlab01_data --> 52% used

As you can see from the output above its nice and clean. Just like the disk details we could also add similar CPU and MEM based checks. Although many IT shops these days are using monitoring tools like BMC Patrol, Nagios, EM12c, Solarwinds and Spiceworks to name a few…..there is nothing wrong with checking the health of your systems on login. Being proactive with server health will prevent long term ill impacts to your environment.

Leave a Reply

Your email address will not be published.