Hope someone can help, I've been pulling my hair out with this one...
I've written a shell script that does a sanity check on our quite extensive Nagios configuration for anything that needs cleaning up but wouldn't make the Nagios daemon necessarily bork or complain.
One section of the script checks our Nagios 'services' configuration, the definition of these services are spread across multiple config files and are laid out something like this...
All definitions for each 'service' are each wrapped in;
I'm using awk to parse these service definitions and I'm attempting to pulling out 4 lines from each definition and print out each with $1 removed in a '~' separated string, e.g.
Thing is that these 4 lines aren't always in the same order within the braces and this is the cause of my woes.
The awk statement I wrote is;
...where "$services" is the output of cat'ing all the services config files.
My awk isn't reliable as it isn't coping with these 4 lines being in different orders and some of the strings being printed are wrong (e.g. a string beginning with a "service_description" from one definition ends in a "check_command" from the next definition in the config file).
So my plea is for someone to point out where I'm going wrong because I've reached my awk limits and copious amounts of RTFM'ing isn't coming up with the answers.
I've gone the route of your 3rd example were I'm conditionally printing the string on the closing brace and notice that you've quite sensibly chosen to use an array of variables. I've changed it slightly so the print occurs when a line ends with the closing brace instead of beginning and ending with a brace, just in case any definitions added in the future are formatted differently.
So my awk now looks like;
My script is now coming out with correct results.
Thanks muchly.
I have an AIX 7.1 LPAR where Nagios agent was installed for monitoring. The issue is that when I start the nagios service (ncpa_listener), it starts but does not open the 5693 port it requires for communication. On all other LPARs the service opens the port and is listening. I tried reinstalling... (4 Replies)
Hello All,
I have setup Nagios 3.2.3 on CentOS release 5.7 (Final) with the default config files and added 1 host to it and it is sending "Service Alert: CentOS 5/HTTP is WARNING" frequently, how do you fix this one? what are the additional files that need to be added so that I can monitor the... (0 Replies)
Hi ,
I have a config _file that has 3 columns (Id Name Value ) with many rows . In my bash script i want to be able to parse the file and do a mapping of any Id value
so if i have Id of say brand1 then i can use the name (server5X) and Value (CCCC) and so on ...
Id Name ... (2 Replies)
Hi I am new to shell scripting. There is a requirement to write a shell script to meet follwing needs.Prompt reply shall be highly appreciated.
script that will compare two config files and produce 2 outputs - actual config file and a report indicating changes made.
OS :Susi linux ver 10.3.
... (4 Replies)
I'm trying to register & start a service using SMF on Solaris 10. It's nsca, part of the Nagios monitoring system. I've got nsca running fine as a detached process, and can manually create passive checks via send_nsca. But when I try to run nsca as a daemon, I need some advice.
The nsca... (0 Replies)
Hi,
i'm trying to parse a config file that have alot of rows similar to this one:
Example value value value
What i want to do is to split and save the row above in a hash, like this:
Example = value value value
Basically i want to split on the first whitespace after the first... (3 Replies)
Hi all, I've done some searching here but haven't found exactly what I'm looking for so I thought I'd post up and see if someone can help out.
I'm working on a shell script that I would like to store environment variables in an external file. I'm familiar with sourcing a file with variables in... (1 Reply)
I am using MKS tool kit on windows server. One config variable is defined in windows environment and I am trying to use that variable.
# Below RootDir is defined in windows
RootDir="\\f01\var"
# in unix script
details="$RootDir/src|$RootDir/tgt"
src=`echo $details|awk -F '|' '{print... (1 Reply)
Hi,
I want to use a config file as the base file and parse over the values of country and city parameters in the config file and generate separate config files as explained below.
I will be using the config file as mentioned below:
(config.txt)
country:a,b
city:1,2
type:b1... (1 Reply)
Hi All,
I have a requirement to parse a file.
Let me clear you all on the req.
I have a job which contains multiple tasks and each task will have multiple attributes that will be in the below format. Each task will have some sequence number according to that sequence number tasks shld... (0 Replies)