Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: Dialog with UNIX shell

by vitaly (Acolyte)
on Jul 19, 2007 at 21:33 UTC ( #627634=note: print w/replies, xml ) Need Help??


in reply to Re^3: Dialog with UNIX shell
in thread Dialog with UNIX shell

No, I am writing the programm which installs ssh keys on remote servers. my @servers = ('j5'); foreach my $server (@servers) { my $cmd = "bash"; if (system($cmd)) { print "$cmd failed\n"; next; } my $res = qx(ssh $server); if ($res =~ m/RSA\skey\sfingerprint/) { HERE I NEED TO ANSWER YES/NO AND PRESS ENTER

Replies are listed 'Best First'.
Re^5: Dialog with UNIX shell
by ikegami (Pope) on Jul 19, 2007 at 21:41 UTC

    You need something like IPC::Open2 instead of qx() since you want 2-way communication with ssh. qx() only allows to receive from the child process.

    That said, you're probably better off using Expect and let it worry about the nitty gritty parent-child communication details.

Re^5: Dialog with UNIX shell
by nedals (Deacon) on Jul 20, 2007 at 01:06 UTC
    If you use (y/n) instead of yes/no, you can do it like this
    my $response = <STDIN>; chomp($response); if (lc($response) eq 'y') { ...etc

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2018-02-25 04:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (312 votes). Check out past polls.

    Notices?