NET:TELNET data output

B

bigdogdan2

Is there a way I can get NET::TELNET to print out the data realtime
instead of after the command is finished?
My command:
@lines = $conn->cmd("./a.sh");
print @lines;

Where a.sh contains:
#!/bin/bash
for i in 1 2 3 4 5 6 7
do
ls /dev
sleep 5
done

Nothing gets outputed until the script finishes

Thanks,
Daniel
 
B

bigdogdan2

Hi,
I couldn't get your suggestion to work.

$conn->print("./a.sh");
while (1) {
my $line = $conn->getline;
print $line;
if ($line == "[root@(none) root]") {
exit;
}
}

actually, I couldn't even get
$conn->cmd('ls /dev');
my $line = $conn->getline;
print $line;

Do you see any problem with this?

Thanks,
Dan
 
J

Jay Rogers

Is there a way I can get NET::TELNET to print out the data realtime
instead of after the command is finished?

You can send the command and read its response a block at a
time:

use Net::Telnet;
$t = new Net::Telnet(-prompt => "/\\Q$prompt\\E\$/");
$t->open($host);
$t->login($user, $passwd);

$t->print("a.sh");

while ($blk = $t->get) {
print $blk;
$buf .= $blk;

last if $buf =~ /\Q$prompt\E$/;
}

or you can just make input_log() (i.e. the bytes read from
the remote host) go to stdout:

$t->input_log(\*STDOUT);
$t->cmd(-string => "a.sh",
-timeout => 60);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top