Monitoring script written in bash


Standard monitoring script for Linux servers.

Monitoring script written in bash

Posted on 2015-10-05 by Peter Bassill in category Guides.


Guides   Remediation  


Standard monitoring script for Linux servers.


#! /bin/bash<# Check if connected to Internet or notping -c 1 google.com &> /dev/null && echo -e "Internet: Connected" || echo -e "Internet: Disconnected"# Check OS Typeos=$(uname -o)echo -e "Operating System Type :" $os# Check OS Release Version and Namecat /etc/os-release | grep 'NAME\|VERSION' | grep -v 'VERSION_ID' | grep -v 'PRETTY_NAME' > /tmp/osreleaseecho -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 Architecturearchitecture=$(uname -m)echo -e "Architecture :" $architecture# Check Kernel Releasekernelrelease=$(uname -r)echo -e "Kernel Release :" $kernelrelease# Check hostnameecho -e "Hostname :" $HOSTNAME# Check Internal IPinternalip=$(hostname -I)echo -e "Internal IP :" $internalip# Check External IPexternalip=$(curl -s ipecho.net/plain;echo)echo -e "External IP : "$externalip# Check DNSnameservers=$(cat /etc/resolv.conf | sed '1 d' | awk '{print $2}'")echo -e "Name Servers :" $nameservers# Check Logged In Userswho>/tmp/whoecho -e "Logged In users :" && cat /tmp/who# Check RAM and SWAP Usagesfree -h | grep -v   > /tmp/ramcacheecho -e "Ram Usages :" cat /tmp/ramcache | grep -v "Swap"echo -e "Swap Usages :"cat /tmp/ramcache | grep -v "Mem"# Check Disk Usagesdf -h| grep 'Filesystem\|/dev/sda*' > /tmp/diskusageecho -e "Disk Usages :" cat /tmp/diskusage# Check Load Averageloadaverage=$(top -n 1 -b | grep "load average:" | awk '{print $10 $11 $12}'")echo -e "Load Average :" $loadaverage# Check System Uptimeuptime=$(uptime | awk '{print $3,$4}' | cut -f1 -d,)echo -e "System Uptime Days/(HH:MM) :" $uptime# Remove Temporary Filesrm /tmp/osrelease /tmp/who /tmp/ramcache /tmp/diskusage


Get in Touch

Kindly fill the form and we will get back to you.

Contact us if you are experiencing a Cyber IncidentHaving a Cyber Incident?