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

Expect Real Time Logs

by anshumangoyal (Scribe)
on May 03, 2012 at 06:20 UTC ( #968641=perlquestion: print w/ replies, xml ) Need Help??
anshumangoyal has asked for the wisdom of the Perl Monks concerning the following question:

I am using Expect.pm to telnet a windows machine, Run a command and capture it's results. This is what I am doing:
use Expect; #Let's assume I am logged in to the Remote machine and $telnet is my E +xpect Handler. my $timeout = undef; my $prompt = "> "; $telnet->send("$command"); $telnet->expect($timeout, '-re', $prompt);
Now my problem is when I send command and wait for expect I want whatever is coming back from the remote machine is captured/printed immediately on screen. If I use $telnet->before() it returns me whole content but that is not real time and I get this variable only after expect block has executed. In other words, I want the expect buffer to flush out immediately as there is some content in it to see the command response in real time. If any one is not able to understand please let me know.

Comment on Expect Real Time Logs
Download Code
Re: Expect Real Time Logs
by Anonymous Monk on May 03, 2012 at 07:41 UTC

    I am using Expect.pm to telnet a windows machine, Run a command and capture it's results. This is what I am doing:

    Don't do that, its not secure. Use ssh2

      This is a windows machine so cannot do SSH to that. The only option left with me is to do a telnet to the machine.

        This is a windows machine so cannot do SSH to that.

        Yes you can. You don't have to use ssh suite of tools, but you have to use encryption.

      Don't do that, its not secure.

      That amounts to Cargo Cult Advice.

      How do you know he's not doing it on a private network not connected to the internet (for example?)

      Maybe you want to say, "your password will go over the wire in plain text if you use telnet." Or something like that. But saying "don't do that" is generally unhelpful and completely antithetical to the spirit of hacking (in the original sense of the word.)

      So, err, don't say that.

      -sauoq
      "My two cents aren't worth a dime.";
Re: Expect Real Time Logs
by sauoq (Abbot) on May 03, 2012 at 12:33 UTC

    I haven't used Expect in a long time but I'm pretty sure you just need to set some pty settings correctly to get what you want. Something like $telnet->stty('-echo') probably.

    I've FP'd your node so hopefully you'll get some more (better) help than I can give at the moment.

    -sauoq
    "My two cents aren't worth a dime.";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://968641]
Approved by moritz
Front-paged by sauoq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-09-16 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (51 votes), past polls