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]