阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux系统监控shell脚本

250次阅读
没有评论

共计 2331 个字符,预计需要花费 6 分钟才能阅读完成。

Linux 系统监控 shell 脚本代码如下,实现了 Linux 系统的一些常见的监控变量,分享给大家。

#=============================#
#Filename=system_monitor.sh
#Author:foxsir
#Date:2016-02-15
#=============================#
#!/bin/sh
clear
if [[$# -eq 0]]
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
#Check if connected To Internet Or Not
    ping -c2 www.baidu.com &>/dev/null && echo -e ‘\E[36m’ “Internet : Connected” || echo ‘\E[36m’ “Internet : Failed”
#Check Logged In Users
    who > /tmp/who
    echo -e ‘\E[36m’ “Operating System Lgged In Users :” $Reset_terminal && cat /tmp/who
    rm -f /tmp/who
#Check OS Memory Userages
    echo -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 Userages
    echo -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 Loadaverage
    echo -e ‘\E[36m’ “Operating System Loadaverage :” $Reset_terminal $(top -n1b | grep “load average” | awk ‘{print $(NF-2) $(NF-1) $NF}’)
#Check OS Diskaverage
    echo -e ‘\E[36m’ “Operating System Diskaverage :” $Reset_terminal $(df -hP | grep -vE “%%|tmpfs” | awk ‘{print $1,$5}’)
#Check OS Runtime
    echo -e ‘\E[36m’ “Operating System Runtime :” $Reset_terminal $(top -n1b | grep “load average” | awk -F”[ ,]+” ‘{print $5}’)
fi

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-04/129980.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2331字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中