linux系统参数统计脚本

Posted flyme123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux系统参数统计脚本相关的知识,希望对你有一定的参考价值。

#!/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 CPU Userages
echo -e ‘\E[36m‘ "Operating System CPU Userages(us,sy,id):" $Reset_terminal  $(top -b -n 1 | grep Cpu | awk -F ‘ ‘ ‘{print $2,$3,$5}‘)
#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

 

 

以上是关于linux系统参数统计脚本的主要内容,如果未能解决你的问题,请参考以下文章

Linux系统shell脚本之统计文本

inotifywait命令常用参数 Linux周末学习

Linux之shell脚本实战统计 Linux 进程相关数量信息

Linux bash基础特性二

linux下如何查看文件夹大小?硬盘使用情况?内存使用情况?

linux中怎么编写shell脚本,首先判断参数个数,若无参数提示(please enter pa