Hello All, I have a file that has the following array format from a nagios .cfg file.
define service { host_name kr-cont00 service_description PING check_command check_host max_check_attempts 1 check_interval 1 retry_interval 2 check_period 24x7 check_freshness 1 contact_groups admins notification_interval 60 notification_period 24x7 notifications_enabled 1 register 1 } define service { host_name KT service_description Check SSH check_command check_ssh max_check_attempts 1 check_interval 1 retry_interval 2 check_period 24x7 check_freshness 1 contact_groups admins notification_interval 60 notification_period 24x7 notifications_enabled 1 register 1 } define service { host_name KT service_description Controller Load check_command check_nrpe!check_load max_check_attempts 1 check_interval 1 retry_interval 2 check_period 24x7 check_freshness 1 contact_groups admins notification_interval 60 notification_period 24x7 notifications_enabled 1 register 1 }
I have a lot of this files that I need to modify the contact_groups for certain services (for example the define service for PING should be skipped). Below is the code below:
#!/usr/bin/perl $input_file="kt.txt"; open FT, "$input_file"; @input = <FT>; close FT; $check = "check_nrpe"; $con = "contact_groups"; foreach $list (@input) { if ($list =~ /PING/) { next; } if ($list =~ /$check/ && $list =~ /$con/) { print "$list\n"; } }
I get no output when I run the script. but if I use the || instead of &&, the output I get contains contact_group output from PING which does not require modification. Thank you for your envisaged response.
In reply to && comparison not working by catalyst_list
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |