標籤:系統資訊 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指令碼