I am trying to assign the output of an expect command to a variable in
my program but I am not having much luck at the moment...

@cfg_dump = print $command "dump\n"  does not seem to want to work.
While in another program I had something like
@data_gathered = `snmp $V1 $V2 $V4`  This would produce about 50 - 300
lines of output and would be in @data_gathered.  With some research I am
thinking that if I am going to use expect and dump data to my @cfg_dump
I am going to have to how I assign my file handle so that I can call
$fh->raw_pty(1);  would I be accurate or am I missing something given
the following code.  For the record, at this point the only part not
working is in my GET_Filters() where I issue a print @cfg_dump.  I think
I am missing the boat some where here..  Any advise (even it is go jump
in a lake.)    ;)

#!/usr/bin/perl

use strict;
use warnings;
use Expect;


### End of global section

############### LOGIN
#########################################################

sub login
{
        my ($command) = @_;

   if ($command->expect(5, "(yes/no)?"))
    {
       print $command "yes\r\n";
       print "\n\nWARNING: Initial run or failure on SSH-Key
acceptance.\n";
    }

   $command->expect(5, '-re','word:\s$') || (die "Never got password
prompt\n");

   print $command "valid_pw\n";
   return;

} # End of sub login

############### GET_Filters
###################################################

sub GET_Filters
{
        my ($command) = @_;
        my @cfg_dump;

  $command->expect(5, '-re','Main#\s$') || (die "Never got Main\n");
  print $command "cfg\n";

  $command->expect(5, '-re','Configuration#\s$')
     || (die "Never got Configuration\n");
  @cfg_dump = $command->send("dump\n");

  $command->expect(5, '-re','Configuration#\s$')
     || (die "Never got Configuration\n");
  print $command "exit\n";

  print "\n************ DUMPING INFO I GATHERED ************\n";
  print @cfg_dump;

}

############### MAIN
##########################################################

        my $command;
        my @settings;
# $user = (getpwuid($<))[0]; ##  Get the user that is running the
program



  $command = Expect->spawn("/usr/bin/ssh vlid_ip")
    || die "Couldn't start program: $!\n";

#  $command->log_stdout(0);

  login ($command);
  GET_Filters($command);

-- 
Leif Ericksen <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to