linux system status script






linux system status script

© by oToGamez 2014




Funny thing with this one is, that there is almost as much code as output might be usefull for sys-admins.
Scripts is pretty optimized but actually only uses some simple system commands and reading from /proc.
You can also do that manually but when you ill try you will see the below procedure is much faster.
In general it goes like that:
-in general we need to check at least 18 variables, to be able to see if system is working corrrectly:
1. server name: hostname #evidence name for server status
2. ssl library version: openssl version #see if you have latest openssl version installed
3. cpu type: cat /proc/cpuinfo #see cpu type
4. cpu usage or load: uptime #check for system load
5. ram and swap usage: cat /proc/meminfo #check for ram and swap usage
6. disk usage: df #check if you have enough of free space
7. system clock: date #check if date is far behind
8. runlevel: runlvel #check if you are running proper set of services
9. active users: w #check if you have some unwanted visitors
10. running processes: top #check if you are running some very demanding processes or if system is producing zombies
11. Open tcp and udp ports: netstat -an #check if you have some unwanted ports opened
12. gateway: route -n #check if your traffic is going through correct router
13. dns: cat /etc/resolv.conf #check if you have resolver IPs entered
14. Network status: ifconfig #check for network settings (IP, mask)
15. Firewall status: iptables --list #check if you are running firewall

But as you will see, there is too much typing to perform proper filtering.
This is already done for you inside this script.

#!/bin/bash
clear;E='echo -n';e=echo;p=proc;v=version;m='model name';ci=cpuinfo;mi=meminfo
t=tput;NUL=/dev/null;$t civis;trap "$e;$t cnorm;exit" 2;n=netstat;h=hostname
u=uname;a=awk;c=cat;BLUE(){ $e -en "\033c\033[1m\033[37;44m\033[J";}
g=grep;IP=$(/sbin/ip addr show|grep inet|awk '{print $2}')
while :;do $t cup 0 0;iptables -L -n 2>$NUL|$g -i 'reject\|drop' >$NUL
if [ "$?" = "0" ];then fw=on;else fw='off!';fi;OUT(){
$E -e "\033[30;42m"
$e " SYSTEM STATUS                                     << update=5s ctrl+c >> "
$E -e "\033[37;44m"
$e "  Server             > $($h) $($u -r) $($c /$p/$v |$a '{print $9,$10,$11}') "
$e "  SSH/SSL            > $(openssl version 2>&1|head -1)  "
$e "  Processor          > $($g "$m" /$p/$ci|$a '{print $4,$5,$6,$7,$8,$9}'|uniq -c)"
$e "  System load        > $($c /$p/loadavg |$a '{print $1,$2,$3}')  "
$e "  Uptime             > $(uptime|cut -f2 -dp|cut -f1 -d,)  "
$e "  SWAP (usage)       > "$($g Swap[Total\|Free] /proc/$mi)"  "
$e "  RAM (usage)        > "$($g Mem[Total\|Free] /proc/$mi)"  "
$e "  Disks usage        > "$(df|$g /|grep -v '/run'|$a '{print $5,$6}')"  "
$e "  Date and time      > $(date)  "
$e "  Runlevel           > $(runlevel)  "
$e "  Logged in Users    > $(users)  "
$e "  Processes          > $(top -b -n1|$g Tasks|cut -f2- -d,|tr -s ' ')  "
$e "  Open ports (tcp)   > "$($n -an|$g 'LISTEN '|$a '{print $4}'|cut -f2 -d:|sort|uniq)"  "
$e "  Open ports (udp)   > "$($n -an|$g ^udp|$a '{print $4}'|cut -f2 -d:|sort|uniq)"  "
$e "  Default Gateway(s) > "$(netstat -rn|$g UG|$a '{print $2}')"  "
$e "  DNS                > "$($g nameser /etc/resolv.conf|$a '{print $2}')"  "
$e "  Net status         > "$IP""
$e "  Firewall           > $fw  "
$E ' ________________________________________________________________________'
};OUT >/tmp/.teststatus;BLUE;$c /tmp/.teststatus;$t cnorm;sleep 5;$t civis;done