系统巡检脚本

系统巡检脚本

检测并输出系统的内存总容量,剩余内存容量,磁盘总容量,剩余磁盘总容量,CPU核心,CPU型号及数量

#!/bin/bash
function network(){
echo "================系统巡检================="
INTERNET=(`ifconfig eth1 |awk -F '[ :]+' '/inet addr/{print $4}'`)
echo "      本机IP:${INTERNET}"
CPUID=`grep "physical id" /proc/cpuinfo |sort|uniq|wc -l`
CPUCORES=`grep "cores" /proc/cpuinfo|sort|uniq|awk -F: '{print $2}'`
CPUMODE=`grep "model name" /proc/cpuinfo|sort|uniq|awk -F: '{print $2}'`

echo "     CPU数量: $CPUID"
echo "     CPU核心:$CPUCORES"
echo "     CPU型号:$CPUMODE"

MEMTOTAL=`free -m|grep Mem|awk '{print $2}'`
MEMFREE=`free -m|grep Mem|awk '{print $7}'`

echo "  内存总容量: ${MEMTOTAL}MB"
echo "剩余内存容量: ${MEMFREE}MB"

disksize=0
swapsize=`free|grep Swap|awk {'print $2'}`
partitionsize=(`df -T|sed 1d|egrep -v "tmpfs|sr0"|awk {'print $3'}`)
for ((i=0;i<`echo ${#partitionsize[*]}`;i++))
do
disksize=`expr $disksize + ${partitionsize[$i]}`
done
((disktotal=\($disksize+$swapsize\)/1024/1024))

echo "  磁盘总容量: ${disktotal}GB"

diskfree=0
swapfree=`free|grep Swap|awk '{print $4}'`
partitionfree=(`df -T|sed 1d|egrep -v "tmpfs|sr0"|awk '{print $5}'`)
for ((i=0;i<`echo ${#partitionfree[*]}`;i++))
do
diskfree=`expr $diskfree + ${partitionfree[$i]}`
done

((freetotal=\($diskfree+$swapfree\)/1024/1024))

echo "剩余磁盘容量:${freetotal}GB"
}

network

你可能感兴趣的:(cpu,linux,操作系统,shell)