Gary,
Basically your code works except for the last 2 lines. I can't for the
life of me figure out why.
my $OS=(&get_response('uname -n'))[0] or die "OS not found" unless ($OS &&
defined $whichos{$OS});
my $response=(&get_response($commands{$OS}{'hostname'}))[0];
print OUTPUT_FH ",$response";
I get no output to response:
My declaration station of commands is like this:
my %commands =
('sol'=>{'hostname' =>'uname -n',
'os' =>'uname -s',
'osver' =>'uname -r',
'osrel' =>'cat /etc/release | awk \'{print $3}\'',
'srvtype' =>'uname -p',
'srvmodel' =>'uname -i | cut -f2 -d ","',
'memory' =>'prtconf | grep Memory | awk \'{print $3}\'',
'cpu' =>'psrinfo | awk \'{print $1}\' | wc -l'}
);
sub get_response {
my @lines = $telnet->cmd($_[0]);
print @lines;
return @lines;
}
I have reduce for now the get_response routine like the above.
I know it works cause I print the $OS variable and it is correct.
But what is funny. Your last line statement should have printed
Something but the results was nothing.
So what am I doing wrong?
Phillip
-----Original Message-----
From: Gary Stainburn [mailto:[EMAIL PROTECTED]
Sent: Tuesday, October 28, 2003 3:04 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: Issue
On Tuesday 28 Oct 2003 5:42 pm, [EMAIL PROTECTED] wrote:
> Gary,
>
> I think your closer to what I was thinking of.
> It makes more sense. Currently, This is what I
> Have so far not with your suggestions as of yet.
>
[snip]
>
> #
> # Get the host name of system
> #
> my @lines = $telnet->cmd('uname -n');
> my $csv = Text::CSV->new;
> if ( $csv->parse(@lines) ){
> my @field = $csv->fields;
> for $host (@field){
> print OUT_FH $host,",", $ipaddr;
> print "Found Host...\n";
> }
> }
Hi Philip,
I'm not sure why you're using Text::CSV in this context, but other than
that,
wouldn't the above be better placed in a subroutine, e.g.
sub get_response(
my @lines = $telnet->cmd($_[0]);
my $csv = Text::CSV->new;
if ( $csv->parse(@lines) ){
return $csv->fields;
}
return undef;
}
then you could simply do (using my answer from before)
my $OS=(&get_response('uname -n'))[0];
die "OS not found" unless ($OS && defined $whichos{$OS});
my $hostname=(&get_response($commands{$OS}{'hostname'}))[0];
print OUTPUT_FH ",$hostname";
etc......
If course, if you made the subroutine only return a single value, it would
be
cleaner to call.
[snip]
>
> So far this is only testing the solaris commands on the network
> I have access to. I appreciate any other comments you may have.
>
>
> -----Original Message-----
> From: Gary Stainburn [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, October 28, 2003 8:36 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: Issue
> y
>
> On Monday 27 Oct 2003 7:32 pm, [EMAIL PROTECTED] wrote:
> > Hi,
> >
> > I'm trying to accomplish some task using perl. So let
> > me describe what I have.
> >
> > I have several systems of the following:
> >
> > Unix:
> > Sun - Solaris
> > HP - HPUX
> >
> > Windows:
> > Dell - Windows 2k
> >
> > Each of these OS's have specific commands that are specific
> > not only to the OS but to the hardware as well. Wouldn't it be
> > better if I created a header file that contains these commands
> > and assigned them to a common variable?
> >
> > Example:
> > $memory = 'prtconf | grep Memory | awk '{print $3}'
>
> [snip]
>
> Hi Philip,
>
> I'd try something like (asuming $detail is part of the header returned
from
> the Net::telnet connect)
>
> my %whichos=('Solarix'=>'sol','Aix'=>'aix','microsoft'=>'W2K');
> my %commands=('sol'=>{'memory'=>'prtconf | grep Memory | awk '{print $3}',
> 'diskfree'=>'..........'}
> 'aix'=>{'memory'=>'.......',
> 'diskfree'=>'......'}
> 'W2k'=>{'memory'=>'........',
> 'diskfree'=>'......'});
>
> my $OS='';
> foreach my $regex (keys %whichos) {
> $OS=$whichos{$regex} if ($details=~/$regex/i);
> }
> die "cannot find OS" unless ( $OS && defined {$commands{$OS});
>
> then simply use %commands{$OS}{memory} to get the command you want
>
> > Phillip Bruce
> > ISC Consultant, System Architect
> > Location: Dublin, CA
> > * Cell: 408-476-8658
> > * Office: 925-560-7853
> > AIM: OkieUnix
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]