Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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.


Comment on Re^3: Issue with Expect
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961145]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2015-07-02 21:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (45 votes), past polls