Pretty much I am using a Nagios plugin to check a Net-App filer and I export all volumes of the NetApp filer's diskusage to a file. I want to parse this file line by line and return each line if it matches a certain phrase (volume name ie. $vol_to_parse). At the same time, the plugin not only produces each volumes disk usage line by line into a text file for me, it also unfortunately reproduces every volume in a nasty mess at the end of the file. This is why I was trying to do: my @arrayz=($raw_data[0]..$raw_data-1);#!/usr/bin/perl use strict; use Getopt::Long; #GetOpt::Long::Configure('bundling'); #sub process_args(); #sub pars0r(); &process_args; &open_sesame; &pars0r; #my $hostname; my $vol_to_parse; my $file_to_parse; my @raw_data; my $status; my $volume; sub process_args(){ $status = GetOptions ( 'v=s' => \$vol_to_parse, # volume to parse argumento 'h=s' => \$file_to_parse); print "Process arg subrountine real\n"; print "Using: "."vol: $vol_to_parse". " and " . "file: $file_to_parse" + . "\n"; } #$file_to_parse="netapp_volume_location"; sub open_sesame{ open(DAT, $file_to_parse) || die("Could not open file! Is it there?"); @raw_data=<DAT>; #Take everything from file and put in @raw_data array close(DAT); print "open and close ran \n"; } #my @arrayz=($raw_data[0]..$raw_data[-1]); print "Gonna print whole array"; print "$raw_data[0..-1]"; my $y = qw ($raw_data[0]..$raw_data[3]); sub pars0r{ # foreach $volume (@arrayz) foreach $volume (@raw_data) { chomp($volume); # print "$volume" . "\n"; if ($volume =~ $vol_to_parse) { print "$vol_to_parse"." ". "got got \n"; } # elsif ($volume !=~ $vol_to_parse) # { # redo; #} else{ print "Did not find volume!\n"; } } }
however my output from my code of a file1.txt with the info contains on 4 seperate lines:
hello
goodbye
john
dillinger
and my output is:
root# perl ult_test.pl -v john -h file1.txt
Process arg subrountine real
Using: vol: john and file: file1.txt
open and close ran
Did not find volume!
Did not find volume!
john got got
Did not find volume!
Gonna print whole arraygoodby.
I only want it to return the line with john in it. Am I going about this all wrong? Any help would be greatly appreciated. Thank you.
Sluggo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |