|
Posted by Natxo Asenjo on June 10, 2008, 6:07 am
Please log in for more thread options
hi,
This should be easy but I do not seem to get right. I want to monitor
the health of a raid controller with nagios. No plugin for it, so I'm
writing my own.
The tool is arcconf.exe and I this is what i have so far (it works, but
the output is not nice enough):
==========begin snippet============================
#!/usr/bin/perl
use warnings;
use strict;
=pod
this script executes "c:\program files\adaptec\adaptec storage
manager\arcconf.exe"
=cut
# here is the program
my $adaptec_installdir = "c:/program files/adaptec/adaptec storage
manager";
# we go to this dir
chdir $adaptec_installdir or die "$!\n" ;
# we execute the program, output is kept in variable $arcconf
my $arcconf = `arcconf\.exe getconfig 1 ad`;
open(OUTPUT, $arcconf) or die "Can't run $arcconf: $!\n" ;
while (<OUTPUT>) {
print $_ ."\n" ;
}
====================end snippet===========================
and this is the output:
Unsuccessful open on filename containing newline at D:\Program
Files\NSClient++-
Win32-0.3.1\scripts\check_adaptec_raid.pl line 28.
Can't run Controllers found: 1
----------------------------------------------------------------------
Controller information
----------------------------------------------------------------------
Controller Status : OK
Channel description : SCSI
Controller Model : 2120S
Controller Serial Number : c65a68
BIOS Version : 4.2-0 (8208)
Firmware Version : 4.2-0 (8208)
Driver Version : 4.2-1 (7372)
Physical Slot : 4
Copyback enabled : No
Background consistency check enabled: No
Defunct disk drive count : 0
Logical devices/Failed/Degraded : 1/0/0
Command completed successfully.
: No such file or directory
if I run the command on cmd.exe this is the output:
C:\Program Files\Adaptec\Adaptec Storage Manager>arcconf.exe getconfig 1
ad
Controllers found: 1
----------------------------------------------------------------------
Controller information
----------------------------------------------------------------------
Controller Status : OK
Channel description : SCSI
Controller Model : 2120S
Controller Serial Number : c65a68
BIOS Version : 4.2-0 (8208)
Firmware Version : 4.2-0 (8208)
Driver Version : 4.2-1 (7372)
Physical Slot : 4
Copyback enabled : No
Background consistency check enabled: No
Defunct disk drive count : 0
Logical devices/Failed/Degraded : 1/0/0
Command completed successfully.
Why am I getting the 'Unsuccessful ..." warnings? How can I get rid of
them?
--
Groeten,
J.I.Asenjo
|
|
Posted by Jacob JKW on June 10, 2008, 6:53 am
Please log in for more thread options
> ==========begin snippet============================
> # we execute the program, output is kept in variable $arcconf
> my $arcconf = `arcconf\.exe getconfig 1 ad`;
>
> open(OUTPUT, $arcconf) or die "Can't run $arcconf: $!\n" ;
> while (<OUTPUT>) {
> print $_ ."\n" ;
>
> }
> ==========end snippet============================
> Why am I getting the 'Unsuccessful ..." warnings? How can I get rid of
> them?
Replace the open() command and while loop with:
print $arcconf;
Or alternatively, replace the backticks in the declaration of the
$arcconf variable with double quotes (or with single quotes after
removing the backslash):
my $arcconf = 'arcconf.exe getconfig 1 ad';
|
|
Posted by Uri Guttman on June 10, 2008, 2:30 pm
Please log in for more thread options
>> ==========begin snippet============================
>> # we execute the program, output is kept in variable $arcconf
>> my $arcconf = `arcconf\.exe getconfig 1 ad`;
>>
>> open(OUTPUT, $arcconf) or die "Can't run $arcconf: $!\n" ;
>> while (<OUTPUT>) {
>> print $_ ."\n" ;
>>
>> }
>> ==========end snippet============================
>> Why am I getting the 'Unsuccessful ..." warnings? How can I get rid of
>> them?
JJ> Replace the open() command and while loop with:
JJ> print $arcconf;
JJ> Or alternatively, replace the backticks in the declaration of the
JJ> $arcconf variable with double quotes (or with single quotes after
JJ> removing the backslash):
JJ> my $arcconf = 'arcconf.exe getconfig 1 ad';
huh? the backslash isn't needed anyhow since that isn't a regex. and
your open will fail as there is no file with that name. you need a |
after the open string to make it fork a process and read its output. for
what the OP wants backticks is much simpler. he just didn't know he had
the data and thought (how did he get that idea?) that it returned a
handle.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
|
|
Posted by Tad J McClellan on June 10, 2008, 7:56 am
Please log in for more thread options
> my $arcconf = `arcconf\.exe getconfig 1 ad`;
At this point you have the output from the command stored in $arcconf.
(the backslash is not needed there...)
> open(OUTPUT, $arcconf) or die "Can't run $arcconf: $!\n" ;
> while (<OUTPUT>) {
> print $_ ."\n" ;
> }
If you want to print the output of the command, then
print $arcconf;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"
|
|
Posted by Eric Pozharski on June 10, 2008, 2:41 pm
Please log in for more thread options *SKIP*
> my $arcconf = `arcconf\.exe getconfig 1 ad`;
> open(OUTPUT, $arcconf) or die "Can't run $arcconf: $!\n" ;
> while (<OUTPUT>) {
> print $_ ."\n" ;
> }
*SKIP*
> Why am I getting the 'Unsuccessful ..." warnings? How can I get rid of
> them?
Because you're trying to open B<output> of C<arcconf.exe getconfig 1 ad>
for... output. I suppose, that yours blah-blah toy blah-blah operating
blah-blah system is unhappy with some characters in filename (perl is
using value of I<$arcconf> as a filename), filename length, whatever.
Reread L<perlopentut>.
#/usr/bin/perl
use strict;
use warnings;
open my $output, '-|', 'arcconf.exe getconfig 1 ad' or
die "can't run arcconf: $?";
while(my $line = <$output>) {
print $line; };
close $output or
die "can't get rid of arcconf: $?";
__END__
I suppose you're going to tinker with output, right? Then remember,
I<$line> still contains trailing C<"\n">.
--
Torvalds' goal for Linux is very simple: World Domination
|
| Similar Threads | Posted | | capture output from print command to variable in perl | April 15, 2005, 4:32 pm |
| command output | March 13, 2008, 2:01 pm |
| FAQ 8.24: Why can't I get the output of a command with system()? | November 29, 2004, 12:03 pm |
| FAQ 8.24: Why can't I get the output of a command with system()? | December 23, 2004, 6:03 pm |
| FAQ 8.24 Why can't I get the output of a command with system()? | March 3, 2005, 6:03 am |
| FAQ 8.24 Why can't I get the output of a command with system()? | May 21, 2005, 11:03 am |
| FAQ 8.24 Why can't I get the output of a command with system()? | August 6, 2005, 10:03 am |
| FAQ 8.24 Why can't I get the output of a command with system()? | September 28, 2005, 10:03 pm |
| FAQ 8.24 Why can't I get the output of a command with system()? | June 26, 2006, 9:03 pm |
| FAQ 8.24 Why can't I get the output of a command with system()? | September 9, 2006, 3:03 am |
|