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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



sonia93
New User

Dec 13, 2007, 12:18 AM

Post #1 of 2 (330 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

$exp->spawn($cmd);

#login and interact
$exp->expect(20,
[ qr/\(yes\/no\)\?\s*$/ => sub {
my $exp=shift;
$exp->send("yes\n");
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 !!
Sonia


Kanji
User / Moderator

Dec 13, 2007, 8:24 PM

Post #2 of 2 (322 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:-


Code
$exp->debug(2); 
$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.).
--k.

 
 


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

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