catalyst_list has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: && comparison not working
by NetWallah (Canon) on Mar 02, 2019 at 05:42 UTC | |
|
Re: && comparison not working (updated)
by AnomalousMonk (Archbishop) on Mar 02, 2019 at 04:56 UTC | |
|
Re: && comparison not working
by hippo (Archbishop) on Mar 02, 2019 at 09:42 UTC | |
by NetWallah (Canon) on Mar 02, 2019 at 15:32 UTC | |
|
Re: && comparison not working
by AnomalousMonk (Archbishop) on Mar 02, 2019 at 07:32 UTC |