Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Responding to terminal I/O

by CountOrlok (Friar)
on Apr 17, 2013 at 18:01 UTC ( #1029188=note: print w/ replies, xml ) Need Help??


in reply to Responding to terminal I/O

This isn't the right way to approach this. When you do system("su"), your program will sit and wait for the su command to finish or timeout before going on the next line of code.

The larger question would be why do you want to do "su"? Are you then going to run certain commands as root? You should instead look into using something like the Expect module.


Comment on Re: Responding to terminal I/O
Download Code
Re^2: Responding to terminal I/O
by cspctec (Sexton) on Apr 17, 2013 at 18:08 UTC
    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.
      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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-08-30 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls