System Monitoring

Categories: Scripts

Short script to output the state of a system.

#! /bin/bash


echo "------------------------------------------------------------------------------------"
# Cheo k if connected to Internet or not
ping -c 1 google.com &> /dev/null && echo -e "Internet:      Connected" || echo -e "Internet:     Disconnected"

# Check if the vpn is up
ifconfig | grep tun &> /dev/null && echo -e  "VPN:           Connected" || echo -e "VPN:          Disconnected"

# Check OS Type
os=$(uname -o)
echo -e "OS Type:      "  $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 "OS Name:       "   && cat /tmp/osrelease | grep -v "VERSION" | cut -f2 -d\"
echo -n -e "OS Version:    "  && cat /tmp/osrelease | grep -v "NAME" | cut -f2 -d\"

# Check Architecture
architecture=$(uname -m)
echo -e "Architecture: "  $architecture

# Check Kernel Release
kernelrelease=$(uname -r)
echo -e "Kernel:       "  $kernelrelease

# Check hostname
echo -e "Hostname:     "  $HOSTNAME

# Check Internal IP
internalip=$(hostname -I)
echo -e "Internal IP:  "  $internalip

# Check External IP
externalip=$(curl -s ipecho.net/plain;echo)
echo -e "External IP:   "$externalip

# Check DNS
nameservers=$(cat /etc/resolv.conf | sed '1 d' | awk '{print $2}')
echo -e "Name Servers: "  $nameservers 
echo -e ""
# Check Logged In Users
who>/tmp/who
echo -e "Logged In:    "  && cat /tmp/who 
echo -e ""
# Check RAM and SWAP Usages
free -h | grep -v + > /tmp/ramcache
echo -e "Ram Usage:    " 
cat /tmp/ramcache | grep -v "Swap"
echo ""
echo -e "Swap Usage:   " 
cat /tmp/ramcache | grep -v "Mem"
echo ""
# Check Disk Usages
df -h| grep 'Filesystem\|/dev/*' > /tmp/diskusage
echo -e "Disk Usages:  "  
cat /tmp/diskusage
echo ""
# Check Load Average
loadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}')
echo -e "Load Average: "  $loadaverage
echo ""
# Check System Uptime
tecuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)
echo -e "Uptime:       "  $tecuptime

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

# Remove Temporary Files
rm /tmp/osrelease /tmp/who /tmp/ramcache /tmp/diskusage
«
»