我需要在一个特定的define service节中更改一个单词,其中service_description是NRPE - NTP_TIME,contact_groups是ops1,我需要更改为ops2,我想这样做以缩短我的工作,因为我需要在多个主机上执行。以下是该文件的片段;例如
define service{
use generic-service
service_description NRPE
is_volatile
check_period
max_check_attempts
check_interval
retry_interval
contact_groups xyz,xyz,ops1,xyz
notification_period 24x7
check_command xyz
}
define service{
use generic-service
service_description NRPE
is_volatile
check_period
max_check_attempts
check_interval
retry_interval
contact_groups xyz,xyz,ops1,xyz
notification_period 24x7
check_command xyz
define service{
use generic-service
service_description NRPE - NTP_TIME
is_volatile
check_period
max_check_attempts
check_interval
retry_interval
contact_groups xyz,xyz,ops2,xyz
notification_period 24x7
check_command xyz
def xd(foo):
with open("plik1.txt", 'r') as f:
lines = f.readlines()
print(lines)
with open("plik1.txt", 'r') as f:
for line in lines:
if 'NRPE - NTP_TIME' in line:
print(lines)
line = line.replace('ops1', 'ops2')
f.write(line)
我不太知道如何编写这段代码,我的意思是,如果服务描述是NRPE-NTP_TIME,那么我只想在这里将ops1更改为ops2。