Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^3: Issue with Expect

by zengargoyle (Deacon)
on Mar 23, 2012 at 03:45 UTC ( #961145=note: print w/replies, xml ) Need Help??

in reply to Re^2: Issue with Expect
in thread Issue with Expect

Why are you terminating sends with "\r" and not "\n"?
#!/usr/bin/env perl use 5.014; use warnings; use Expect; my $exp = Expect->new; $exp->spawn('ssh tak'); $exp->expect(10, '~$ '); # prompt. using ssh keys so no password $exp->send("ls\n"); $exp->expect(10, '~$ '); $exp->send("exit\n"); $exp->soft_close(); __END__ Output: zengargoyle@tak:~$ ls ... ls output ... zengargoyle@tak:~$ exit logout Connection to tak closed.
I would guess that the password input is accepting the "\r" as an input terminator (because login/password type input is wonky like that) but the proper input terminator for the type of session input and for general shell commands is "\n".

Just a guess, unless your Solaris is wonky or running some special shell (not csh/sh/etc) you should be using "\n". I've done a bunch of Expect stuff with Solaris, routers, switches, ... over ssh and never have I used "\r". I always use "\n" and have never had the sort of problem you seem to be having.

Replies are listed 'Best First'.
Re^4: Issue with Expect
by azstyx (Acolyte) on Mar 23, 2012 at 20:32 UTC
    Yes, I was just posting the resolution. You are absolutely correct! I just discovered that Solaris 8 likes to have it's responses and commands terminated with \n and not \r. I actually have used \r for connecting to network appliances and never had a problem. What threw me off was I sent the user login password as "$passw\r" and it worked ok. I have updated all my send commands to use \n instead of \r. All is well now. Thanks!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961145]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2018-06-22 23:27 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.