系統資訊採集的shell指令碼

來源:互聯網
上載者:User

標籤:系統資訊   shell指令碼   

#!/bin/bash
ip=$(ip a | grep "inet "| awk ‘{print $2}‘ | awk -F/ ‘{print $1}‘ | grep -v 127.0.0.1 | awk ‘BEGIN{RS=‘\n‘}{$1=$1;print $0}‘ | sed ‘s/ /,/g‘)  #取出除過127.0.0.1的所有ip,用“,”隔開

hostname=$(hostname)

cpu_num=$(cat /proc/cpuinfo | grep processor | wc -l)

mem_size=$(expr $(free -g | grep "Mem:" | awk ‘{print $2}‘) + 1)

disk_size=$(expr $(df | grep ‘/data.*‘ | awk ‘{print $(NF-4)}‘ | awk ‘BEGIN{sum=0}{sum=sum+$1}END{print sum}‘) / 1048576)   #計算除過系統硬碟的外的其它掛載盤的大小,伺服器上往往會掛載一塊比較大的盤,並不使用系統硬碟

NIC=$(ip a | grep "inet " | grep -v "lo$" | grep -v " secondary "|grep -v "wlan.*"|grep -v "vir.*" | awk ‘{print $NF}‘)    #統計所有除過本地迴環,虛擬網卡外的網卡名

adapter1=$(for nic in $NIC
    do
        speed=$(ethtool $nic | grep "Speed" | awk ‘{print $2}‘)
        driver=$(ethtool -i $nic  | grep "driver" | awk ‘{print $2}‘)
        driver_version=$(ethtool -i $nic  | grep "^version" | awk ‘{print $2}‘)
        printf ‘%s %s %s %s,‘ $nic $speed $driver $driver_version
    done)
adapter=$(echo $adapter1 | sed -n ‘s/,$//p‘)    #列出所有的網卡資訊,包括網卡名,網卡頻寬,網卡驅動及其驅動版本,網卡資訊中間用“,”隔開

os=$(cat /etc/issue | sed -n ‘1p‘ | awk ‘{print $1$2$3}‘)

kernel=$(uname -r)

int_ip=$(ip a | grep "inet "| grep -v secondary | grep eth1 | awk ‘{print $2}‘ | awk -F/ ‘{print $1}‘)    #取出內網ip,要求內網綁定在eth1上

系統資訊採集的shell指令碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.