服务器:192.168.21.133 一、主机列表 [root@zyl nagios]# cat host.list lvs-01 192.168.1.1 lvs-02 192.168.1.2 mysql-01 192.168.1.3 mysql-02 192.168.1.4 web-01 192.168.1.5 web-02 192.168.1.6 二、部署脚本 [root@zyl nagios]# cat create_host.sh #!/bin/sh HOSTFILE='/usr/local/nagios/etc/objects' cat >>$HOSTFILE/host_test.cfg<<EOF ##################################################### # # HOST DEFINITION BY ZHANGYILING AT 20190816 # ##################################################### EOF exec <host.list while read line do echo "#host:`echo $line|awk '{print $1}'`|ip:`echo $line|awk '{print $2}'`">>$HOSTFILE/host_test.cfg echo "define host {" >>$HOSTFILE/host_test.cfg echo " use linux-server">>$HOSTFILE/host_test.cfg echo " hostnmae `echo $line|awk '{print $1}'`">>$HOSTFILE/host_test.cfg echo " alias `echo $line|awk '{print $1}'`">>$HOSTFILE/host_test.cfg echo " address `echo $line|awk '{print $2}'`">>$HOSTFILE/host_test.cfg echo "}">>$HOSTFILE/host_test.cfg echo >>$HOSTFILE/host_test.cfg done >tmp.host exec <host.list i=1 while read line do if [ $i -eq 6 ];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` cat >>$HOSTFILE/host_test.cfg<<EOF ##################################################### # # HOST GROUP DEFINITION BY ZHANGYILING AT 20190816 # ##################################################### define hostgroup{ hostgroup_name linux-servers alias Linux Servers members $members } EOF
转载于:https://blog.51cto.com/zhagyilig/1857867