CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
working on perl expect


New User

Dec 13, 2007, 12:18 AM

Post #1 of 2 (729 views)
working on perl expect Can't Post

Hi , I am using expect in perl script to log in remotely to another machine. The code is something like this :
$exp = new Expect();
$cmd = ssh username1@hostname1


#login and interact
[ qr/\(yes\/no\)\?\s*$/ => sub {
my $exp=shift;
exp_continue; } ],
[ $prompt => sub {
my $exp=shift;
$exp->send("$password\n"); } ]) or die "NORMAL LOGIN FAILED\n";

After this I am trying to get on to root on host machine as in order to execute one command , it needs root authority , hence am doing :

$exp->send(" su root\n") || die "SU command failed";

this particular statement is failing repeatedly. After logging as root I want to send another command to generate the ssh key pair like

$exp->send("ssh-keygen -t rsa\n");

But its not logging in as root. Is there something like one cannot log in as root using any other remote script like perl expect ? I really need help in this.

Thanks a lot !!

User / Moderator

Dec 13, 2007, 8:24 PM

Post #2 of 2 (721 views)
Re: [sonia93] working on perl expect [In reply to] Can't Post

I don't believe send() is intended to be checked for success like that, so you might want to try skipping the "|| die ...".

Better would be to enable debugging to see what's going on:-

$exp->send("su root\n");

That should give you some clues about what's going wrong (su might not be in your path or hung at a prompt that Expect doesn't know to look for, send() might not have returned any output, etc.).


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives