189 8069 5689

Linux如何用脚本查看系统信息

Linux如何用脚本查看系统信息?这篇文章运用了实例代码展示,代码非常详细,可供感兴趣的小伙伴们参考借鉴,希望对大家有所帮助。                                                           

成都创新互联公司是一家专业提供南召企业网站建设,专注与网站制作、做网站、H5高端网站建设、小程序制作等业务。10年已为南召众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。

#!/bin/bash
# auth:Bertram
# created Time : 2019-12-26
# func:sys info check
# sys:centos6.x/7.x
-------------------------------------------------------------------------------------------------------------------------------------
[ $(id -u) -ne 0 ] && echo "请用root用户执行此脚本!" && exit 1
sysversion=$(rpm -q centos-release|cut -d- -f3)
line="-------------------------------------------------"
[ -d logs ] || mkdir logs
#sys_check_file="logs/$(ip a show dev eth0|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}')-`date +%Y%m%d`.txt"
sys_check_file="logs/$(ifconfig |awk 'NR==2{print $2}')-`date +%Y%m%d`.txt"
# 获取系统cpu信息
function get_cpu_info() {
    Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l)
    Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
    CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}')
    CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
    CPU_Arch=$(uname -m)
#echo -e '\033[32m CPU信息:\033[0m'
echo -e '\033[05;32m CPU信息:\033[0m'
cat <&1)
    pub_ipadd=$(curl -s http://dDNS.oray.com/checkip | awk -F ":"  '{print $2}' | awk -F "<"  '{print $1}'|awk '{print $1}')
    gateway=$(ip route | grep default | awk '{print $3}')
    mac_info=$(ip link| egrep -v "lo"|grep link|awk '{print $2}')
    dns_config=$(egrep 'nameserver' /etc/resolv.conf)
    route_info=$(route -n)
echo -e '\033[05;33m IP信息:\033[0m'
cat </dev/null)
    if [ ${sysversion} -gt 6 ];then
        service_config=$(systemctl list-unit-files --type=service --state=enabled|grep "enabled")
        run_service=$(systemctl list-units --type=service --state=running |grep ".service")
    else
        service_config=$(/sbin/chkconfig | grep -E ":on|:启用" |column -t)
        run_service=$(/sbin/service --status-all|grep -E "running")
    fi
echo -e '\033[05;36m 服务启动配置:\033[0m'
cat </dev/null|cut -d/ -f5;egrep -v "^$|^#" ${cronuser} 2>/dev/null;echo "";done)
echo -e '\033[05;37m 系统登录用户:\033[0m'
cat < ${sys_check_file}

结果如图 :
Linux如何用脚本查看系统信息

关于用脚本查看Linux系统信息的脚本就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


网站栏目:Linux如何用脚本查看系统信息
本文地址:http://cdxtjz.cn/article/ishdhs.html

其他资讯