码迷,mamicode.com
首页 > 系统相关 > 详细

shell编程-实例之输出系统信息

时间:2016-01-20 17:21:30      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

输出系统信息

#!/bin/bash

if [ $# -eq 0 ];then

        echo "---------------------------------------------------------------------------"
        # OS Type
        echo "                    OS Type: $(uname -o)"

        # OS Release Version and Name
        echo "OS Release Version and Name: $(cat /etc/issue | head -n 1)"

        #Architecture
        echo "               Architecture: $(uname -m)"

        #Kernel Release
        echo "             Kernel Release: $(uname -r)"

        #hostname
        echo "                   hostname: $HOSTNAME"

        #Internal IP
        echo "                Internal IP: $(hostname -I)"

        #External IP
        echo "                External IP: $(curl -s ipecho.net/plain)"

        #DNS
        dnsservers=""
        for i in $(cat /etc/resolv.conf | grep ‘^nameserver‘ | awk ‘{print $NF}‘)
        do
                dnsservers="$dnsservers$i "
        done

        echo "                        DNS: $dnsservers"

        #if connected to Internet or not
        echo "            internet status: $( ping -c 2 www.baidu.com &> /dev/null && echo ‘connected‘ || echo ‘disconnected‘)"

        echo "---------------------------------------------------------------------------"

fi

 

输出结果:

                    OS Type: GNU/Linux
OS Release Version and Name: CentOS release 6.6 (Final)
               Architecture: x86_64
             Kernel Release: 2.6.32-504.el6.x86_64
                   hostname: wap
                Internal IP: 192.168.110.173 
                External IP: 218.30.109.26
                        DNS: 218.30.105.51 219.141.140.10 
            internet status: connected

  

shell编程-实例之输出系统信息

标签:

原文地址:http://www.cnblogs.com/jackgaolei/p/5145764.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!