执行getinfo.sh脚本后,不需要任何参数,输出内容如下:
$ bash getinfo.sh
cpu num: 2
memory total: 2.8G
memory free: 329M
disk size: 10G
system bit: 32
process: 32
software num: 944
ip: 192.168.1.9

解释:
CPU数量(cpu num)
总内存(memory total),单位为 G
可用内存(memorty free),单位为 M
挂载到 / 根目录的文件系统的总大小(disk size),单位为 G
系统位数(system bit)
当前系统正在运行的进程数(process)
查看已安装的软件包数量(software num)
eth0的ip地址(ip)

shell脚本如下:
#!/bin/bash
a=cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
b=free -m | grep Mem | awk '{print $2}'
c=free -m | grep Mem | awk '{print $4}'
d=df -h | sed -n 3p | awk '{print $1}'
e=getconf LONG_BIT
f=ps auxw | wc -l
h=yum list installed | wc -l
i=ifconfig eth0 | sed -n 2p | awk -F ":" '{print $2}' | awk '{print $1}'
echo "\$bash getinfo.sh"
echo "cpu num:$a"
echo "memory total:${b}M"
echo "memory free:${c}M"
echo "disk size:$d"
echo "system bit:$e"
echo "process:$f"
echo "software num:$h"
echo "ip:$i"