A simple example of Net::SSH::Expect..this simply connects through ssh then check the prompt then sends a command or input..
my $ssh= Net::SSH::Expect->new( host => $host,
password=> $password,
user => $user,
raw_pty =>1,
log_file => $outputfile."\.raw"
);
$ssh->login();
$ssh->send("sudo su");
if ($ssh->peek(1)=~/Password\:/ig){######check if Password prompt come
+s up###
$ssh->send("supassword");
}
my $commandline=$ssh->eat($ssh->peek(1));
$commandline=~ s/Password\://g; #####remove string "Password:"
$commandline=~ s/su|sudo su//g; #####remove string "su" or "sudo su"
$commandline=~ s/^\s+|\s+$//g; ####remove trailing and leading whites
+paces
sorry for my regex..i know its bad..=p
i hope the example helps
P.S. please do not forget to use strict and warnings..=) |