歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

system_monitor.sh

########################################################################################
# File Name: system_monitor.sh
########################################################################################
#!/bin/bash
clear

if [[ $# -eq 0  ]]
 then
 #define variable reset_terminal
 reset_terminal=$(tput sgr0)
 #check OS type
	os=$(uname -o)
	echo -e '\E[32m' "os type:"$reset_terminal $os
 #check OS release version and name
	os_name=$(cat /etc/issue | grep -e "Server")
	echo -e '\E[32m' "os release version and name:"$reset_terminal $os_name
 #check architecture
	architecture=$(uname -m)
	echo -e '\E[32m' "architecture:"$reset_terminal $architecture
 #check kernel release
	kernelrelease=$(uname -r)
	echo -e '\E[32m' "kernel release:"$reset_terminal $kernelrelease
 #check hostname
	hostname=$(hostname)
	echo -e '\E[32m' "hostname:"$reset_terminal $hostname
 #check internal ip
	internalip=$(hostname -i)
	echo -e '\E[32m' "internal ip:"$reset_terminal $internalip
 #check external ip
	externalip=$(curl -shttp://ipecho.net/plain) 	echo -e '\E[32m' "external ip:"$reset_terminal $externalip
 #check dns
	dns=$(cat /etc/resolv.conf | grep -E "\<nameserver[ ]+" | cut -d " " -f2)
	echo -e '\E[32m' "dns:"$reset_terminal $dns
 #check if connected to internet or not
	ping -c 2 baidu.com >> /dev/null && echo "Internal:Connected" || echo "Internal:Disconnected"
 #check logged in users
	who > /tmp/who
	echo -e '\E[32m' "logged in users:"$reset_terminal && cat /tmp/who
	rm -rf /tmp/who

fi

 #system use 系統使用內存
       systemUserage=$(awk '/MemTotal/{total=$2}/MemFree/{free=$2}END{print (total-free)/1024}'   /proc/meminfo)
       echo -e '\E[32m' "systemUserage:"$reset_terminal $systemUserage'M'
 #application usr 應用使用內存
       applicationUserage=$(awk '/MemTotal/{total=$2}/MemFree/{free=$2}/^Cached/{cache=$2}/Buffers/{buffer=$2}END{print (total-free-cache-buffer)/1024}'   /proc/meminfo)
       echo -e '\E[32m' "applicationUserage:"$reset_terminal $applicationUserage'M'

 #load average 操作系統負載
      	loadaverage=$(top -n 1 -b | grep 'load average' | awk '{print $11 $12 $13}')
 	echo -e '\E[32m' "loadaverage:"$reset_terminal $loadaverage
 #磁盤使用率
	dfused=$(df -hP | grep -vE 'Filesystem|tmpfs' | awk '{print $1" "$5}')
	echo -e '\E[32m' "dfused:"$reset_terminal $dfused
Copyright © Linux教程網 All Rights Reserved