shell脚本实现Linux系统监控

运行结果如下所示:
shell脚本实现Linux系统监控_第1张图片

代码如下:

#!/bin/bash
function bule(){
                echo -ne "\e[32m$1\e[0m"
        }

/usr/bin/clear

bule 'Internet: '
[ ping -c 2 www.baidu.com &> /dev/null ] && echo 'connected' || echo 'disconnected'

bule 'Operating System Type: '
echo "`uname -o`"

bule 'Architecture: '
echo "`uname -i`"

bule 'Kerbel Release: '
echo "`uname -r`"

bule 'Internal IP: '
#echo "`ifconfig|grep -A2 'eth0'|grep 't '|awk -F '[ :]+' '{print $4}'`"
echo "ifconfig| grep -A2 ens33 | grep 't '|awk '{print $2}'"

bule 'External IP: '
echo "`curl -s ipecho.net/plain;echo`"

bule 'Name Servers: '
echo "`cat /etc/resolv.conf | grep 'nameserver '|awk '{print $2}'`"

bule 'Logged In users: '
echo
echo "`who`"

bule "Ram Usages: "
echo
echo "`free -h | sed -n '1,2p'`"

bule "Swap Usages: "
echo
echo "`free -h| sed -n '1p'`"
echo "`free -h| sed -n '4p'`"

bule "Disk Usages: "
echo
echo "`df -h | grep 'Filesystem\|/dev/sda*'`"

bule "Load Average: "
echo "`top -bn1 |head -1 |awk -F ',' '{print $1}'|awk '{print $5,$6}'`"

你可能感兴趣的:(shell)