Script for Server Health Check

#################################################################################
# This Script is written by – Jitendra Bauddha                                                                                # #################################################################################
#! /bin/bash
# (copy paste there lines and in a file and save file with .sh extention and give u+x permission)

# clear the screen
clear

unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage

while getopts iv name
do
case $name in
i)iopt=1;;
v)vopt=1;;
*)echo “Invalid arg”;;
esac
done

if [[ ! -z $iopt ]]
then
{
wd=$(pwd)
basename “$(test -L “$0” && readlink “$0” || echo “$0″)” > /tmp/scriptname
scriptname=$(echo -e -n $wd/ && cat /tmp/scriptname)
su -c “cp $scriptname /usr/bin/monitor” root && echo “Congratulations! Script Installed, now run monitor Command” || echo “Installation failed”
}
fi

if [[ ! -z $vopt ]]
then
{
echo -e “Server_health monitor version 1.0nDesigned by Jitendra BauddhanReleased Under Apache 2.2 License”
}
fi

if [[ $# -eq 0 ]]
then
{

# Define Variable tecreset
tecreset=$(tput sgr0)

# Check if connected to Internet or not
ping -c 1 google.com &> /dev/null && echo -e ‘E[32m'”Internet: $tecreset Connected” || echo -e ‘E[32m'”Internet: $tecreset Disconnected”

# Check OS Type
os=$(uname -o)
echo -e ‘E[32m'”Operating System Type :” $tecreset $os

# Check OS Release Version and Name
cat /etc/os-release | grep ‘NAME|VERSION’ | grep -v ‘VERSION_ID’ | grep -v ‘PRETTY_NAME’ > /tmp/osrelease
echo -n -e ‘E[32m'”OS Name :” $tecreset && cat /tmp/osrelease | grep -v “VERSION” | cut -f2 -d”
echo -n -e ‘E[32m'”OS Version :” $tecreset && cat /tmp/osrelease | grep -v “NAME” | cut -f2 -d”

# Check Architecture
architecture=$(uname -m)
echo -e ‘E[32m'”Architecture :” $tecreset $architecture

# Check Kernel Release
kernelrelease=$(uname -r)
echo -e ‘E[32m'”Kernel Release :” $tecreset $kernelrelease

# Check hostname
echo -e ‘E[32m'”Hostname :” $tecreset $HOSTNAME

# Check Internal IP
internalip=$(hostname -I)
echo -e ‘E[32m'”Internal IP :” $tecreset $internalip

# Check External IP
externalip=$(curl -s ipecho.net/plain;echo)
echo -e ‘E[32m'”External IP : $tecreset “$externalip

# Check DNS
nameservers=$(cat /etc/resolv.conf | sed ‘1 d’ | awk ‘{print $2}’)
echo -e ‘E[32m'”Name Servers :” $tecreset $nameservers

# Check Logged In Users
who>/tmp/who
echo -e ‘E[32m'”Logged In users :” $tecreset && cat /tmp/who

# Check RAM and SWAP Usages
free -h | grep -v + > /tmp/ramcache
echo -e ‘E[32m'”Ram Usages :” $tecreset
cat /tmp/ramcache | grep -v “Swap”
echo -e ‘E[32m'”Swap Usages :” $tecreset
cat /tmp/ramcache | grep -v “Mem”

# Check Disk Usages
df -h| grep ‘Filesystem|/dev/sda*’ > /tmp/diskusage
echo -e ‘E[32m'”Disk Usages :” $tecreset
cat /tmp/diskusage

# Check Load Average
loadaverage=$(top -n 1 -b | grep “load average:” | awk ‘{print $10 $11 $12}’)
echo -e ‘E[32m'”Load Average :” $tecreset $loadaverage

# Check System Uptime
tecuptime=$(uptime | awk ‘{print $3,$4}’ | cut -f1 -d,)
echo -e ‘E[32m'”System Uptime Days/(HH:MM) :” $tecreset $tecuptime

# Unset Variables
unset tecreset os architecture kernelrelease internalip externalip nameserver loadaverage

# Remove Temporary Files
rm /tmp/osrelease /tmp/who /tmp/ramcache /tmp/diskusage
}
fi
shift $(($OPTIND -1))

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s