如果管理的站点和服务器较多的情况下,每次修改配置文件都相当痛苦。因而想到了用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
如果存在大量需要手工修改配置文件的情况下,或者批量生成一些类似的文件时可以考虑采用此种方式。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]