Shell 系统信息监控脚本

 

vim system_monitor.sh

#!/bin/bash
clear
if [[ $# -eq 0 ]]
then
#
reset_terminal=$(tput sgr0)

# Check OS Type
        os=$(uname -o)
        echo -e '\E[32m'"Operating System Type :" $reset_terminal $os
# Check OS Release Version and Name
        os_name=$(cat /etc/issue|grep -e "Server")
        echo -e '\E[32m'"Check OS Release Version and Name :" $reset_terminal $os_name
# Check Architecture    
        architecture=$(uname -m)
        echo -e '\E[32m'"Check architecture :" $reset_terminal $architecture
# Check Kernel Release
        kernelrelease=$(uname -r)
        echo -e '\E[32m'"Check Kernel Release :" $reset_terminal $kernelrelease
# Check hostname
        hostname=$HOSTNAME
# Check Internal IP
        internalip=$(hostname -I)
        echo -e '\E[32m'"Check Internal IP :" $reset_terminal $internalip
# Check External IP
        externalip=$(curl -s http://ipecho.net/plain)
        echo -e '\E[32m'"Check External IP :" $reset_terminal $externalip
# Check DNS
        nameservers=$(cat /etc/resolv.conf | grep -E "\<nameserver[ ]+"|awk '{print $NF}'i)
        echo -e '\E[32m'"Check DNS :" $reset_terminal $nameservers
# Check if connected to Internet or not
        ping -c 2 imooc.com &>/dev/null && echo "Internet:Connected" || echo "Internet:Disconnected"
# Check Logged In Users
        who>/tmp/who
        echo -e '\E[32m' "Logged In Users" $reset_terminal && cat /tmp/who
        rm -f /tmp/who
fi

 

内存中cache和buffer的区别

 

posted @ 2024-08-31 12:01  ~技术小白  阅读(8)  评论(0编辑  收藏  举报