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

Re^2: perl expect moudule to interact with Linux terminal

by kkbka (Initiate)
on Mar 30, 2015 at 17:36 UTC ( [id://1121875]=note: print w/replies, xml ) Need Help??


in reply to Re: perl expect moudule to interact with Linux terminal
in thread perl expect moudule to interact with Linux terminal

Thanks for your reply. I tried with autoexpect also but no luck.

Kindly let me know, how to escape the "#" in perl. I tried like "\#", but its not escaping, instead of that it assumes the following character are commented

  • Comment on Re^2: perl expect moudule to interact with Linux terminal

Replies are listed 'Best First'.
Re^3: perl expect moudule to interact with Linux terminal
by pme (Monsignor) on Mar 30, 2015 at 21:47 UTC
    This little piece of code works for me. Beside replacing '???' at $user and $pass you should also replace '\$' with '#' in all three cases.
    use strict; use Expect; my $user = "???"; my $pass = "???"; my $hostname = "localhost"; my $comm1 = "pwd"; my $comm2 = "date"; my $comm3 = "exit"; $Expect::Log_Stdout = 1; my $session = Expect->spawn("ssh $user\@$hostname") or die "Error call +ing external program: $!\n"; $session->expect(5,"password: "); $session->send("$pass\r"); $session->expect(5, "\r \$"); $session->send("$comm1\r"); $session->expect(5, "\r \$"); $session->send("$comm2\r"); $session->expect(5, "\r \$"); $session->send("$comm3\r"); $session->expect(undef);

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-23 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found