我正在尝试在看起来相似的巨大文本文件中添加 nagios 服务检查。我想搜索每个主机名(作为模式)并在四行之后附加新的服务检查块。该脚本应该能够在每次出现 host_name 之后附加新的服务检查块。
OR
想在两个连续的行上搜索两个模式,并在文本文件中每次出现时在两个搜索到的模式之间插入下面的文本块。
P1 - notification_options d,r P2 - }
我只知道 sed 的基础知识,任何帮助都将不胜感激。
define service{
use new
host_name new
active_checks_enabled 0
check_freshness 0
service_description new
check_command new
check_period 24x7
}
define host{
use linux
host_name lotus
alias lotus
address 10.1.1.1
notification_options d,r
}
define service{
use linux
host_name lotus
active_checks_enabled 0
check_freshness 0
service_description Host Alive
check_command check-host-alive
check_period 24x7
}
define service{
use linux
host_name lotus
active_checks_enabled 0
check_freshness 0
service_description CPU
check_command check_cpu!95!100
check_period 24x7
notification_options w,c,r
}
define host{
use linux
host_name palm
alias palm
address 10.1.1.2
notification_options d,r
}
define service{
use linux
host_name palm
active_checks_enabled 0
check_freshness 0
service_description Host Alive
check_command checki_host
check_period 24x7
}
define service{
use linux
host_name palm
active_checks_enabled 0
check_freshness 0
service_description CPU
check_command check_cpu!95!100
check_period 24x7
notification_options w,c,r
}
define host{
use linux
host_name geeko
alias geeko
address 10.1.1.3
notification_options d,r
}
define service{
use linux
host_name geeko
active_checks_enabled 0
check_freshness 0
service_description Host Alive
check_command check_alive
check_period 24x7
}
define service{
use linux
host_name geeko
active_checks_enabled 0
check_freshness 0
service_description CPU
check_command check_cpu!95!100
check_period 24x7
notification_options w,c,r
}