‘sup.sh’ – What’s up on this server?

I have a script that I use to determine some quick stats on a server.  The script is called ‘sup.sh’.  I’ll post it here for your enjoyment, entertainment, and possible usage.

#!/bin/bash
{

IFS=$'\n'

### PULL THE SYSTEM INFORMATION ###
UPTIME=`uptime`
D_UP=`uptime | awk '{ s = ""; for (i = 1; i <= NF; i++) s = s $i " "; print s }'`
MYGROUPS=`groups`
KERNEL=`uname -a`
CPWD=`pwd`
ME=`whoami`
NOW=`date +"%A, %B %e, %Y - %Y/%m/%d - %l:%M %p %Z (%z)"`
DISKUSAGE=`df -h`
COMPILED=`cat /proc/version`

if [ -f /etc/redhat-release ] ; then
DISTRIBUTION=`cat /etc/redhat-release`
else
DISTRIBUTION=`lsb_release -a | awk '/Description:/{
i=2
while(i<NF){
printf $i
if(i<NF){
printf " "
}
i++
}}'`
fi

if [ -z "$DISTRIBUTION" ]; then
DISTRIBUTION=`head -n 1 /etc/issue`
fi

MEMORY=`free -mt | awk '/Mem/{print "\tTotal: "$2"Mb\tUsed: "$3"Mb\tFree: "$4"Mb"}'`
SWAP=`free -mt | awk '/Swap/{print "\tTotal: "$2"Mb\tUsed: "$3"Mb\tFree: "$4"Mb"}'`

#Potential to contain multiple ethernet adaptors
NETWORKADAPTOR=`ip -o addr | awk '/inet /{print $2}' | grep -v lo`
if [ `ethtool $NETWORKADAPTOR | awk '/Link detected:/{print $3}'` == "yes" ]; then
LINK="Cable Connected"
else
LINK="Unknown"
fi

GATEWAY=`/sbin/route -n | awk '/^0.0.0.0/{printf $2}'`

if [ `arch` == "i686" ]; then
ARCH="32-bit System"
elif [ `arch` == "x86_64" ]; then
ARCH="64-bit System"
else
ARCH="Unknown architecture"
fi

NUMPROCS=`cat /proc/cpuinfo | grep -i processor | wc -l`
PROCNAME=`cat /proc/cpuinfo | grep -i "model name" | head -n 1 | awk '
/model\ name/{
i=4
while(i<=NF){
printf $i
if(i<NF){
printf " "
}
i++
}
printf "\n"
}'`

#LASTLOGGED=`lastlog | awk "/$ME/"'{print $3" "$4" "$5" "$6" "$7" "$8}'`
LASTLOGGED=`lastlog | awk "/$ME/"'{
i=4
while(i<=NF){
printf $i
if(i<NF){
printf " "
}
i++
}
}'`

LASTLOGGED=`lastlog | grep -i ${ME} | awk '{ s = ""; for (i = 2; i <= NF; i++) s = s $i " "; print s }'`

CURRLOGINS=`who | cut -f 1 -d " " | sort | uniq`

NUMPROCESS=`ps aux --no-headers | wc -l`

clear

### DISPLAY INFO - BEGIN WITH THE SYSTEM-RELATED INFORMATION ###
printf "<=== SYSTEM ===>\n"
printf "\tSystem Time:\t"
printf "$NOW\n"
printf "\tDistribution:\t"
printf "$DISTRIBUTION\n"
printf "\tKernel:\t\t"
printf "$KERNEL\n"
printf "\tCompiled:\t"
printf "$COMPILED\n"
printf "\tUptime:\t\t"
printf "$D_UP\n"
printf "\tProcesses:\t"
printf "$NUMPROCESS\n"
printf "\tSwap:\t"
printf "$MEMORY\n"
printf "\tMemory:\t"
printf "$SWAP\n"
printf "\tArchitecture:\t"
printf "$ARCH\n"
printf "\tProcessors:\t"
printf "$NUMPROCS x $PROCNAME\n"

VMWARE_CHECK=`lspci | grep -i vmware | wc -l`
if [ $VMWARE_CHECK -gt 0 ]; then
printf "\tVirtualization:\tVMWare\n"
fi

printf "\tDisk Usage:\n"

for DISKLN in $DISKUSAGE
do
echo " $DISKLN"
done

printf "\tUsers currently logged in:\n"

for CURRUSER in $CURRLOGINS
do
printf "\t\t$CURRUSER\n"
done


#printf "\t\t$CURRLOGINS\n"

### DISPLAY USER-RELATED INFORMATION ###
printf "\n""<=== USER ===>\n"
printf "\tCurrent User:\t"
printf "$ME (uid:$UID)\n"
printf "\tUser's Groups:\t"
printf "$MYGROUPS\n"
printf "\tWorking dir:\t"
printf "$CPWD\n"
printf "\tHome dir:\t"
printf "$HOME\n"
printf "\tLast login:\t"
printf "$LASTLOGGED\n"
printf "\tDesktop:\t"
printf "$DESKTOP_SESSION\n"


### DISPLAY NETWORK-RELATED INFORMATION ###
printf "\n""<=== NETWORK ===>\n"
printf "\tHostname:\t"
printf "$HOSTNAME\n"

for ADDR in `ip -o addr | awk '/inet /{print "(" $2 "):\t" $4}'`
do
printf "\tInterface "
printf "$ADDR\n"
done

printf "\tLink Status:\t"
printf "$LINK\n"


printf "\tGateway:\t"
printf "$GATEWAY\n"

for NS in `cat /etc/resolv.conf | awk '/^nameserver/{ printf $2 "\n"}'`
do
printf "\tName Server:\t"
printf "$NS\n"
done
} 2> /dev/null

# see if we can determine the external IP address as seen from the Internet
EXT_IP="`wget -qO- -oConnectTimeout=5 http://icanhazip.com`"
printf "\tExternal IP:\t$EXT_IP\n"

If this melts your house, it’s not my fault.  But it has always worked for me just fine.  Enjoy.