获取服务器 内核、CPU、内存、磁盘等信息。
kel=`uname -r`
os=`awk -F '"' '/^PRETTY_NAME/ {print $(NF-1)}' /etc/os-release`
server_info=`dmidecode -t 1 |grep -P 'Manufacturer:|Product Name:|Serial Number:'|tr -d '\t'`
memory_info=`dmidecode -t 17|tr -d '\t'|grep -P 'Size:|^Locator:|Type:|Speed:Manufacturer:|Serial Number:'`
ip=`hostname -i`
cpu=`lscpu|grep -Pi '^CPU\(|Model Name:'`
echo "主机名: $(hostname) | IP: ${ip}"
echo "CPU:"
echo $cpu
echo "内核: ${kel} | OS: ${os}"
echo "服务器信息: ${server_info}"
echo "内存信息 ${memory_info}"
echo "磁盘信息 $(lsblk|awk '/disk/ {print $1,$4}')"
如果用 Ansible 执行:
ansible all -i inventory.ini -m script -a "getinfo.sh" |sed '/stdout":/ d' |sed '/stderr/ d'