shell获取系统信息

来自:互联网
时间:2018-08-25
阅读:

直接上代码:

#!/bin/bash
#show ip
sys_ip=`/sbin/ifconfig |grep "inet addr"|awk '{print $2}'|awk -F: '{print $2}'`
echo "IP List:${sys_ip}"
#show cpu info
cpu_cores=`cat /proc/cpuinfo |grep -i "cpu cores"`
echo "${cpu_cores}"
cpu_hz=`cat /proc/cpuinfo |grep -i "cpu MHz"`
echo "${cpu_hz}"
cpu_id=`vmstat |tAIl -n 1|awk '{print $15}'`
cpu_use=`expr 100-${cpu_id}`
echo "Cpu Use:${cpu_use}%"
#show mem info
mem_total=`cat /proc/meminfo |grep -i "MemTotal"|awk '{print $2}'`
echo "Total Mem:${mem_total} kB"
mem_free=`vmstat |tail -n 1|awk '{print $3}'`
mem_buffers=`vmstat |tail -n 1|awk '{print $4}'`
mem_cached=`vmstat |tail -n 1|awk '{print $5}'`
mem_use=`expr ${mem_total} -${mem_free} -${mem_buffers} -${mem_cached}`
echo "Mem Use:${mem_use} kB"
返回顶部
顶部