ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to read certain lines within a file and give the output of the certain lines that dont equal my value, I think showing you would be easier.
There is multiples of these inside one file.......
Code:
LV Name /dev/vg00/lvol1
LV Status available/syncd
LV Size (Mbytes) 300
Current LE 75
Allocated PE 75
Used PV 1
LV Name /dev/vg00/lvol2
LV Status available/syncd
etc...
I want to read everything in the file, if the status is not available then it should display the name (directly above status). If they are all availbale then do nothing.
I think I know how to do it which includes putting the info in string form and placing in hash but it is proving to be out of my skill range.
Any help is accepted!
Last edited by jack.barnes; 03-16-2011 at 04:40 AM.
Grail - I am afraid the nature of the work has to be written in perl and it is actually a nagios plugin I am creating (believe it or not the nagios part of it is the easiest)
After banging my head against the wall for days, I have come up with nothing, not helpful I am aware. The following things I have down but all jumbled up just so I know what im doing!
Code:
cat mirror_status_data #diplays data
open my $output_fh, "******"
while (<$output_fh>){
my $line=$_;
$line=~s/\s+//g;
Everything has been pretty helpfull so far, but im not there yet, unfortunately.
The status varies between different things, so I am after anything that is not "available" or "available/synced". Wherever this occures in the file I want to display the line above it else print "ok"
#!/usr/bin/perl -w
#check_mirror_statuss
#This plugin will allow the user to check the mirror status' and give a CRITICAL message if the status is not available.
#Author: Jack Barnes
#Version: v1.0
#This program is free software. You may copy or redistribute it under the same terms as Perl itself.
use Getopt::Long;
use warnings;
use strict;
my $file_name = "MIRROR_STATUS";
sub main {
#Counting number of current processes
open my $output_fh, 'mirror_status_data';
#Searching file
while (<$output_fh>){
#Deciding if Warning or Critical message is needed
if ("***LV status != available"){
print "****lv name";
print "$file_name CRITICAL - mirror status = ***LV name";
exit;
}
else{
print "$file_name OK";
exit;
}
}
}
main ();
I have placed **** where the code needs to go, but its got me a little confuffled!
Last edited by jack.barnes; 03-16-2011 at 09:29 AM.
So I find it a little hard to follow your logic based on the variable names, ie you have a variable called file_name but it isn't used when you open the file but is used for the message??
But using your current data, the following seems to work for me:
Code:
#!/usr/bin/perl -w
open my $input, f2;
my $keep = '';
while (<$input>)
{
if ( $_ =~ /Status/ && $_ !~ /available(\/synced)?$/ )
{
print $keep;
}
else
{
$keep = $_;
}
};
close $input
I am guessing the 'if' is the most important part for you as the rest is fairly standard stuff.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.