说明:
脚本通过本地执行check_snmp命令,获取远程linux操作系统版本,并将信息写入文本中
#!/bin/bash
awk {'print $1'} list.txt |while read line
do
echo $line
info=`/usr/local/nagios/libexec/check_snmp -H $line -C public -o sysDescr.0`
centos63=`echo $info | grep 2.6.32-279`
centos62=`echo $info | grep 2.6.32-220`
centos56=`echo $info | grep 2.6.18-238`
if [ -n "$centos63" ];then
echo "centos63"
sed -i "s/$line/$line CentOS6.3/g" list_1.txt
fi
if [ -n "$centos62" ];then
echo "centos62"
sed -i "s/$line/$line CentOS6.2/g" list_1.txt
fi
if [ -n "$centos56" ];then
echo "centos56"
sed -i "s/$line/$line CentOS5.6/g" list_1.txt
fi
echo "---------"
done
192.168.12.2 root123
list_1.txt
192.168.12.2 CentOS6.3 root123