The code below, implements some common monitoring variables of the Linux system, shares to everybody @. [Email protected]
#=============================# #Filename=system_monitor.SH#Author: foxsir#date: .- Geneva- the#=============================##!/bin/SHClearif[[$#-eq0 ]] Then#Define Variable reset_terminal reset_terminal=$ (tput sgr0) #Check os Type os=$(uname-o)Echo-E'\e[36m' "Operating System Type:"$Reset _terminal $OS #check OS realease Version and Name os_name=$(Cat/etc/issue |grep "Server") Echo-E'\e[36m' "Operating System realease Version:"$Reset _terminal $OS _name#check Architecture Architecture=$(uname-m)Echo-E'\e[36m' "Operating System Architecture:"$Reset _terminal $Architecture #check Kernel realease kernel_realease=$(uname-R)Echo-E'\e[36m' "Operating System Kernel realease:"$Reset _terminal $Kernel _realease#check Hostname Hostname=$(hostname) Echo-E'\e[36m' "Operating System Hostname:"$Reset _terminal $Hostname #check Internal IP internal_ip=$(hostname-I)Echo-E'\e[36m' "Operating System Internal IP:"$Reset _terminal $Internal _ip#check External IP external_ip=$ (curl-s http://Ipecho.net/plain) Echo-E'\e[36m' "Operating System External IP:"$Reset _terminal $External _ip#check DNS DNS=$(Cat/etc/resolv.conf |grep "/<nameserver[]+"|awk '{print $NF}') Echo-E'\e[36m' "Operating System DNS:"$Reset _terminal $DNS #checkifconnected to the Internet Or notPing-C2 www.baidu.com &>/dev/NULL&&Echo-E'\e[36m' "internet:connected"||Echo '\e[36m' "internet:failed"#Check logged in UsersW.H.O.>/tmp/W.H.O. Echo-E'\e[36m' "Operating System lgged in Users:"$Reset _terminal &&Cat/tmp/W.H.O. RM-f/tmp/W.H.O.#Check OS Memory useragesEcho-E'\e[36m' "Operating System Memory userages:"$Reset _terminal $ (Cat/proc/meminfo |awk '/^memtotal/{memtotal=$2}/^memfree/{memfree=$2}end {print (memtotal-memfree)/1024, "M"}') #Check App Memory useragesEcho-E'\e[36m' "App Memory userages:"$Reset _terminal $ (Cat/proc/meminfo |awk '/^memtotal/{memtotal=$2}/^memfree/{memfree=$2}/^buffers/{buffers=$2}/^cached/{cached=$2}end {print ( memtotal-memfree-buffers-cached)/1024, "M"}') #Check OS loadaverageEcho-E'\e[36m' "Operating System loadaverage:"$Reset _terminal $ (top-n1b |grep "Load Average"|awk '{print $ (NF-2) $ (NF-1) $NF}') #Check OS diskaverageEcho-E'\e[36m' "Operating System diskaverage:"$Reset _terminal $ (DF-HP |grep-ve"%%|tmpfs"|awk '{print $1,$5}') #Check OS RuntimeEcho-E'\e[36m' "Operating System Runtime:"$Reset _terminal $ (top-n1b |grep "Load Average"|awk-F"[ ,]+" '{print $}')fi
Linux system monitoring shell script