BASH – Generic Linux report scripts.

These scripts are generic reporting scripts that provide general information regarding CPU-Filesystem-RAM usage, uptime, detection if the server is a VMware server or not, Version of Operating System, active TCP sockets and more. These scripts can entered in a for loop and run on multiple servers in order to get an overall picture of the servers.

#GENERIC LINUX REPORT SCRIPT
clear
#storage_space=`df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; ' | awk '{print $5" "$6}' | egrep -v 'boot'`
report_time=`date | awk '{print $4}'`
storage_space=`df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; ' | egrep -v 'boot|tmpfs'`
memory_used=`sar -r 1 | awk '{print $5}' | sed -n '4p'`
cpu_idle=`mpstat  | awk '{print $11}' | tail -1`
cpu_user_load=`sar 1 | grep  -B 1 'Average' | awk '{print $4}' | sed -n '1p'`
cpu_system_load=`sar 1 | grep  -B 1 'Average' | awk '{print $6}' | sed -n '1p'`
uptime_days=`uptime | awk '{print $3 " " $4}' | sed '$s/,//'`
sockets_tcp=`grep 'orphan' /proc/net/sockstat | awk '{print $2 " " $3}'`
#sockets_udp=`grep 'UDP' /proc/net/sockstat | awk '{print $2 " " $3 }'`
#CALCULATE SWAP USAGE
swap_total=`free -m | tail -1 | awk '{print $2}'`
swap_used=`free -m | tail -1 | awk '{print $3}'`
swap_prentage_used=`echo "(( $swap_used / $swap_total ) * 100)" | bc -l | cut -c 1-4`
#-----------------------------------------------------
#----------FUNCTION VMWARE OR NOT---------------------
function hypervisor()
{
dmesg | grep -i 'vmware' >> /dev/null  2>&1
if [[ $? -eq 0 ]];
then status="Virtual"
#printf "\t""\t""This is a VMware Virtual Machine""\n"
echo $status
else
#printf "\t""\t""This is Physical Machine""\n"
status="Physical"
echo $status
fi
 }
existance=$(hypervisor)

#---------FUNCTION OS VERSION---------------------
function Operating_SystemVersion_info ()
{
V_Server_Name=`hostname`
V_OS_Version=`cat /etc/redhat-release`
echo "Host: $V_Server_Name   $V_OS_Version";
}
version=$(Operating_SystemVersion_info)

#-----
echo "________________________________________________________________________________________________________________________________"
echo "TimeStamp: $report_time"
echo "$version  $existance"
echo ""
echo "CPU_Idle  Memory_Used       Swap_Used       CPU/USER       CPU/SYSTEM     UPTIME        SOCKETS/TCP              "
echo "$cpu_idle     $memory_used%              $swap_prentage_used%              $cpu_user_load           $cpu_system_load        $uptime_days       $sockets_tcp                   "
echo ""
#echo "DISK USAGE"
echo "$storage_space"
#echo "________________________________________________________________________________________________________________________________"
#echo $swap_prentage_used
#POSTGRES SERVER REPORT
clear
#storage_space=`df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; ' | awk '{print $5" "$6}'| egrep -v 'boot'`
report_time=`date | awk '{print $4}'`
storage_space=`df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; ' | egrep -v 'boot|tmpfs'`
memory_used=`sar -r 1  | awk '{print $5}' | sed -n '4p'`
cpu_idle=`mpstat  | awk '{print $11}' | tail -1`
cpu_user_load=`sar 1 | grep  -B 1 'Average' | awk '{print $4}' | sed -n '1p'`
cpu_system_load=`sar 1 | grep  -B 1 'Average' | awk '{print $6}' | sed -n '1p'`
uptime_days=`uptime | awk '{print $3 " " $4}' | sed '$s/,//'`
sockets_tcp=`grep 'orphan' /proc/net/sockstat | awk '{print $2 " " $3}'`
#sockets_udp=`grep 'UDP' /proc/net/sockstat | awk '{print $2 " " $3 }'`

#CALCULATE SWAP USAGE
swap_total=`free -m | tail -1 | awk '{print $2}'`
swap_used=`free -m | tail -1 | awk '{print $3}'`
swap_prentage_used=`echo "(( $swap_used / $swap_total ) * 100)" | bc -l | cut -c 1-4`
#-----------------------------------------------------
#----------FUNCTION VMWARE OR NOT---------------------
function hypervisor()
{
dmesg | grep -i 'vmware' >> /dev/null  2>&1
if [[ $? -eq 0 ]];
then status="Virtual"
#printf "\t""\t""This is a VMware Virtual Machine""\n"
echo $status
else
#printf "\t""\t""This is Physical Machine""\n"
status="Physical"
echo $status
fi
 }
existance=$(hypervisor)

#---------FUNCTION OS VERSION---------------------
function Operating_SystemVersion_info ()
{
V_Server_Name=`hostname`
V_OS_Version=`cat /etc/redhat-release`
echo "Host: $V_Server_Name   $V_OS_Version";
}
version=$(Operating_SystemVersion_info)

#-------FUNCTION POSTGRESQL CHECK---------------------
function postgres_status()
{
ps -ef | ps -ef | grep 'postmaster' | grep -v 'grep' >> /dev/null 2>&1
if [[ $? -eq 0 ]];
then postgres_status="Running"
echo $postgres_status
else postgres_status="Down"
echo $postgres_status
fi
}
database_engine=$(postgres_status)
#-----
echo "_________________________________________________________________________________________________________________________________"
echo "TimeStamp: $report_time"
echo "$version  $existance"
echo ""
echo "CPU_Idle  Memory_Used       Swap_Used    POSTGRES     CPU/USER       CPU/SYSTEM     UPTIME        SOCKETS/TCP              "
echo "$cpu_idle     $memory_used%               $swap_prentage_used%        $database_engine        $cpu_user_load           $cpu_system_load        $uptime_days     $sockets_tcp                  "
#echo "DISK USAGE"
echo "$storage_space"
#echo $swap_prentage_used
#APACHE SERVER REPORT
clear
#storage_space=`df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; ' | awk '{print $5" "$6}' | egrep -v 'boot'`
report_time=`date | awk '{print $4}'`
storage_space=`df -Ph | perl -ne 'chomp; printf "\n%-40s %8s %8s %8s %8s %-20s", split / +/, $_, 6 ; ' | egrep -v 'boot|tmpfs'`
memory_used=`sar -r 1 | awk '{print $5}' | sed -n '4p'`
cpu_idle=`mpstat  | awk '{print $11}' | tail -1`
cpu_user_load=`sar 1 | grep  -B 1 'Average' | awk '{print $4}' | sed -n '1p'`
cpu_system_load=`sar 1 | grep  -B 1 'Average' | awk '{print $6}' | sed -n '1p'`
uptime_days=`uptime | awk '{print $3 " " $4}' | sed '$s/,//'`
sockets_tcp=`grep 'orphan' /proc/net/sockstat | awk '{print $2 " " $3}'`
#sockets_udp=`grep 'UDP' /proc/net/sockstat | awk '{print $2 " " $3 }'`
#CALCULATE SWAP USAGE
swap_total=`free -m | tail -1 | awk '{print $2}'`
swap_used=`free -m | tail -1 | awk '{print $3}'`
swap_prentage_used=`echo "(( $swap_used / $swap_total ) * 100)" | bc -l | cut -c 1-4`
#-----------------------------------------------------
#----------FUNCTION VMWARE OR NOT---------------------
function hypervisor()
{
dmesg | grep -i 'vmware' >> /dev/null  2>&1
if [[ $? -eq 0 ]];
then status="Virtual"
#printf "\t""\t""This is a VMware Virtual Machine""\n"
echo $status
else
#printf "\t""\t""This is Physical Machine""\n"
status="Physical"
echo $status
fi
 }
existance=$(hypervisor)

#---------FUNCTION OS VERSION---------------------
function Operating_SystemVersion_info ()
{
V_Server_Name=`hostname`
V_OS_Version=`cat /etc/redhat-release`
echo "Host: $V_Server_Name   $V_OS_Version";
}
version=$(Operating_SystemVersion_info)

#-------FUNCTION APACHE CHECK---------------------
function apache_status()
{
ps -ef | ps -ef | grep 'httpd' | grep -v 'grep' >> /dev/null 2>&1
if [[ $? -eq 0 ]];
then apache_status="Running"
echo $apache_status
else apache_status="Down"
echo $apache_status
fi
}
web_service=$(apache_status)
#-----
echo "_________________________________________________________________________________________________________________________________"
echo "TimeStamp: $report_time"
echo "$version  $existance"
echo ""
echo "CPU_Idle  Memory_Used     Swap_Used    WebService     CPU/USER       CPU/SYSTEM     UPTIME        SOCKETS/TCP              "
echo "$cpu_idle     $memory_used%               $swap_prentage_used%           $web_service        $cpu_user_load           $cpu_system_load          $uptime_days       $sockets_tcp                 "
#echo "DISK USAGE"
echo "$storage_space"

Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.