![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| processing file names using text files | ligander | Shell Programming and Scripting | 5 | 12-01-2008 06:32 PM |
| Problems with extracting information | c0mrade | Shell Programming and Scripting | 0 | 11-17-2008 04:17 PM |
| Extracting data from text file based on configuration set in config file | suparnbector | Shell Programming and Scripting | 3 | 08-10-2007 02:25 AM |
| Extracting information from text fields. | spindoctor | UNIX for Dummies Questions & Answers | 24 | 06-09-2007 01:17 PM |
| Extracting information from a template | Ernst | Shell Programming and Scripting | 4 | 03-07-2007 01:18 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Hello All,
This is my first post on this forums, which I consider one of the best of its kind. The reason for my post is that I want to export some information form Nagios configuration files to a DB. I know that there are other tools available to do this, like NDO, monarch, etc... But I want to do it my self as I have different requests and I will like to improve my scripting capabilities ![]() This is an example from hosts.cfg file: Code:
# 'SACVMW02' host definition
define host{
use generic-host ; Name of host template to use
host_name SACVMW02
alias ESX SERVER
address 10.10.10.110
check_command check-host-alive
contact_groups NETWORKSGDL,CSG,DBAS,OPSGSSC
notification_interval 30
notification_period 24x7
notification_options d,r
}
# 'CALUX901' host definition
define host{
use generic-host ; Name of host template to use
host_name CALUX901
alias Calgary Unix Servers
address 10.120.240.16
check_command check-host-alive
contact_groups MONITORING,CAL-UNIX-ADMINS,NETWORKSGDL
notification_interval 60
notification_period 24x7
notification_options d,r
}
Any suggestion is welcome, I already did some scripts that do the job using grep, sed and awk; reading line by line, but I think that there are other easier approaches that might improve the script, like reading text blocks instead of lines.... Thank you all! Carlos |
|
||||
|
hope below perl can help a little.
Just put them in 8 different array. Code:
#!/usr/bin/perl
$n=0;
open FH,"<a.txt";
while(<FH>){
next if /(\{|#)/;
$n++ if /\}/;
my @tmp=split(/ */,$_,3);
$tmp[2]=~s/;.*//;
$user[$n]=$tmp[2] if $tmp[1] eq "use";
$host_name[$n]=$tmp[2] if $tmp[1] eq "host_name";
$alias[$n]=$tmp[2] if $tmp[1] eq "alias";
$address[$n]=$tmp[2] if $tmp[1] eq "address";
$check_command[$n]=$tmp[2] if $tmp[1] eq "check_command";
$contact_groups[$n]=$tmp[2] if $tmp[1] eq "contact_groups";
$notification_interval[$n]=$tmp[2] if $tmp[1] eq "notification_interval";
$notification_period[$n]=$tmp[2] if $tmp[1] eq "notification_period";
$notification_options[$n]=$tmp[2] if $tmp[1] eq "notification_options";
}
|
|
||||
|
Quote:
Another quick question Summer_cherry, how can I do a multi-dimensional array for Contact Groups, Notifications periods and notification options? As you can see in the example, those have different options separated by comma. Is there an easy way to extract those ? Again, thank you for your support, your script was very helpful and by far better than my existing solution Regards, Carlos |
|
||||
I answer to my self, I used split()Thank you! Carlos |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| awk, nagios, scripting, sed, text processing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|