您的位置:首页 > 运维架构 > Shell

Ubuntu下获取系统信息shell脚本

2018-01-04 20:05 316 查看
#!/bin/bash

# 获取系统信息
# 获取cpu数量
get_cpu_num(){
grep "cpu cores" /proc/cpuinfo | head -n1 | awk '{ print $NF }'
}
# 获取总内存
get_memory_total(){
free -h | awk 'NR==2{ print $2 }'
}
# 获取可用内存
get_memory_free(){
free -m | awk 'NR==2{ print $NF }'
}
# 获取挂载到根目录的文件系统的总大小
get_disk_size(){
df -h | grep -E "^.*/$" | awk '{ print $2 }'
}
# 获取系统位数
get_system_bit(){
getconf LONG_BIT
}
# 获取当前系统正在运行的进程数
get_process(){
ps aux | tail -n +2 | wc -l
}
# 获取已安装的软件包数量
get_software_num(){
dpkg -l | tail -n +6 | wc -l
}
# 获取ip
get_ip(){
ip a s | grep -w "inet" | awk 'NR==2{ print $2 }' | awk -F/ '{ print $1 }'
}

echo "cpu num: $(get_cpu_num)"
echo "memory total: $(get_memory_total)"
echo "memory free: $(get_memory_free)M"
echo "disk size: $(get_disk_size)"
echo "system bit: $(get_system_bit)"
echo "process: $(get_process)"
echo "software num: $(get_software_num)"
echo "ip: $(get_ip)"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: