#!/usr/bin/perl -w use Expect; #use diagnostics; $\ = "\n"; my $user = 'administrator'; my $password = 'password'; my $timeout = undef; my $exp; my $ip = '192.168.5.106'; my $result; my @command_op; sub Login { $exp = Expect->new(); $exp->debug(2); $exp->spawn ('ssh', '-l', $user, $ip); $exp->log_file("Results.log"); $exp->expect($timeout, '-re', "$user\@$ip\'s password: \$"); $exp->send ("$password\n"); } sub CountArray { $exp->expect($timeout, 're', "$user\@cli>"); @command_op = expect_execute('phydrv'); } ## This subroutine was taken from [Expect command output parser sub] sub expect_execute($) { $exp->clear_accum(); my $command = shift; my $x = ''; my $temp = ''; ##Removed 3 lines frm original because command was being passed without a ; at the end. my @temp; print $exp "$command\n"; ##Just printing $command."\n", as opposed to what was done in the original subroutine. $exp->expect($timeout, 're', "$user\@cli>"); ##Didnt really understand what was being done in the original, so this is what I thought should have been here. my $result = $exp->exp_before(); ##This line just dosen't work, Ive tried it as a direct call in the outer code, but get the same results:( ( my @result ) = split( /\n/, $result ); $result = ''; foreach $x ( @result ) { $temp = $x; if ( chop( $temp ) eq "\r" ) { chop( $x ); } push (@temp, $x); } return @temp; } sub Logout { $exp->expect($timeout, 're', "$user\@cli>"); $exp->send("logout\n"); $exp->soft_close(); } Login; CountArray; Logout; #print $result; print join ("\n", @result); #### (...the login subroutine's output is here...) administrator@cli> phydrv =============================================================================== PdId Model Type CfgCapacity Location OpStatus ConfigStatus =============================================================================== 1 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot1 OK Unconfigured 2 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot2 OK Unconfigured 3 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot3 OK Unconfigured 4 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot4 OK Unconfigured 5 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot5 OK Unconfigured 6 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot6 OK Unconfigured 7 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot7 OK Unconfigured 8 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot8 OK Unconfigured 9 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot9 OK Unconfigured 10 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot10 OK Unconfigured ...(some more entries actually come here, followed by 2 new lines this one being one of them) administrator@cli> administrator@cli> logout (...the logout subroutine's output is here...) #### phydrv =============================================================================== PdId Model Type CfgCapacity Location OpStatus ConfigStatus =============================================================================== 1 WDC WD2503 SAS HDD 232.83 GB Encl1 Slot1 OK Unconfigu