如果管理的站点和服务器较多的情况下,每次修改配置文件都相当痛苦。因而想到了用shell脚本来批量生成配置文件和配置数据。下面这个脚本是为了批量生成nagios监控配置文件的一个shell脚本程序。其原理是事先定义一个shell脚本模板,然后每个需要监控的站点复制一份模板替换掉模板文件里面的变量。
1、准备模板文件webcheck.template
more webcheck.template ###################WEBURL define start################### define service{ use generic-service ; Name of service template to use host_name webcheck service_description WEBURL check_command check_webpage!-H WEBURL -u INDEX is_volatile 0 max_check_attempts 3 check_interval 1 retry_interval 1 check_period 24x7 notification_interval 5 notification_period 24x7 notification_options w,u,r,c contact_groups admins } ###################WEBURL define end###################
变量为WEBURL和INDEX
2、站点列表文件weblist.txt
复制代码 代码如下:
www.aaa.com \\/
bbs.bbb.com \\/
www.ccc.com \\/
weblist.txt有两个field,第一个field为域名,第二个field为站点对应的url。如第一个域名为www.aaa.com/
3、批量生成脚本文件create.sh
[root@bogon webcheckes]# more create.sh #!/bin/bash PATH=/bin:$PATH:$HOME/bin:/sbin:/usr/bin:/usr/sbin export PATH #echo $PATH usage () { echo -en "USAGE: $0 [web list] or $0 [template] [web list]\nFor example: $0 host.template host.list(Field : [WEB URL] [INDEX WEB PAGE])\n" 1>&2 exit 1 } if [ $# -gt 2 ];then usage exit 1 fi case "$#" in 2) template=$1 host_list=$2 ;; 1) template='webcheck.template' host_list=$1 ;; 0) # template='webcheck.template' # host_list='host.list' usage ;; esac if [ ! -f "${template}" ];then echo "template : ${template} not exist!" 1>&2 exit 1 fi if [ ! -f "${host_list}" ];then echo "host list : ${host_list} not exist!" 1>&2 exit 1 fi #echo $PWD/${host_list} WEBTEMP="wcalltemp.txt" rm $PWD/${WEBTEMP} #cat $PWD/${host_list} /bin/cat $PWD/${host_list}| while read weburl index do #echo "${ip}"|grep -oP '^\d{1,3}(\.\d{1,3}){3}$' >/dev/null 2>&1 || Field='not ip' #if [ "${Field}" = 'not ip' ];then # echo "${ip} not ip!" 1>&2 # exit 1 #fi #host_cfg="${hostname}-${ip}.cfg" tmppage="webtemp.txt" cp ${template} ${tmppage} sed -i "s/WEBURL/${weburl}/g;s/INDEX/${index}/g" ${tmppage} /bin/cat ${tmppage}${WEBTEMP} done /bin/cat webcheck_org.template>webcheck_${host_list}.cfg /bin/cat ${WEBTEMP}webcheck_${host_list}.cfg rm $PWD/${WEBTEMP} /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg service nagios restart
起作用的主要是这句,sed -i "s/WEBURL/${weburl}/g;s/INDEX/${index}/g" ${tmppage},说到底是sed命令的功劳。将weblist.txt里面的内容替换掉模板里的WEBURL和INDEX变量。
4、调用方式
复制代码 代码如下:
sh ./create.sh webcheck.template weblist.txt
或者
复制代码 代码如下:
sh ./create.sh weblist.txt
如果存在大量需要手工修改配置文件的情况下,或者批量生成一些类似的文件时可以考虑采用此种方式。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 《国语老情歌 容易受伤的女人 2CD》[WAV+CUE][930MB]
- 《蛋仔派对》冒险家闪宝皮肤图鉴
- 《蛋仔派对》红舞裙皮肤图鉴
- 《蛋仔派对》街头小桶皮肤图鉴
- 大原櫻子《Passion》24-96
- 极品四重奏《百年流声2cd》DTS-ES6.1/WAV
- 群星《超级低音终结者-2》UPDTS-WAV分轨
- NS2再爆:8 英寸屏幕、磁性Joycon、解决摇杆磨损
- 《塞尔达》新作存在帧率问题 60/30FPS反复横跳
- 时隔十年!《异形:隔离》续作官宣开发中
- 《魔兽世界》钓鱼路线攻略
- 《生化危机2》mac版发售日期
- 《超级键盘侠》硬核模式怎么开
- 群星.2022-问天录电视剧原声专辑【听见时代】【FLAC分轨】
- 谭嘉仪.2018-LONELY【星梦娱乐】【WAV+CUE】