Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: Responding to terminal I/O

by cspctec (Sexton)
on Apr 17, 2013 at 18:08 UTC ( #1029190=note: print w/replies, xml ) Need Help??

in reply to Re: Responding to terminal I/O
in thread Responding to terminal I/O

I am trying to write a script that will simulate a superuser log in attempt failure, but I'm not sure how to send a password to the terminal when the terminal requests a password.

Replies are listed 'Best First'.
Re^3: Responding to terminal I/O
by CountOrlok (Friar) on Apr 17, 2013 at 19:00 UTC
    this should get you started:
    use strict; use warnings; use Expect; my $timeout = 5; my $password = "password"; my $shell_prompt = ']$ '; my $exp = new Expect; $exp->raw_pty(1); $exp= Expect->spawn("su") or die "Error calling su: $!\n"; unless ($exp->expect(5,"Password: ")) { die; # add error handling }; $exp->send("$password\n"); unless ($exp->expect(5, $shell_prompt)) { die; # add error handling }; print "Login successful\n";

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2018-03-20 02:57 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (247 votes). Check out past polls.