前言
自动生成services.cfg,将不同的服务放置在不同的文件内,便于批量管理和维护。
脚本
[root@nagios_scripts nagios_scripts]# cat nagios_create_service.sh
#!/bin/sh
HOSTPATH="/usr/local/nagios/etc/services"
>tmp.host
exec <host.list
i=1
while read line
do
if [ $i -eq 10 ];then
echo -n "`echo $line|awk ‘{print $1}‘`" >>tmp.host
else
echo -n "`echo $line|awk ‘{print $1}‘`", >>tmp.host
fi
((i++))
done
members=`head -1 tmp.host`
for SERVICENAME in load mem iostat swap disk
do
cat >>$HOSTPATH/$SERVICENAME.cfg<<EOF
define service {
use generic-service
host_name $members
service_description $SERVICENAME
check_command check_nrpe!check_$SERVICENAME
}
EOF
done
本文出自 “挨刀客” 博客,请务必保留此出处http://chboy.blog.51cto.com/9959876/1719229
原文:http://chboy.blog.51cto.com/9959876/1719229