A bit more detail on what you're trying to accomplish might provide us with the ability to point you in a better direction. Absent that, have you looked at Net::Telnet for getting data from a telnet session? You can do whatever you want with the data coming back, including punting it to a file, and even flushing it immediately.
| [reply] |
I have perl script that reads lines from a file and does all kinds of parsing and such. I am not allowed to touch that script. I just need something to connect to the ip port and read in the lines from thqt socket (telnet) session and output each line to a file so this sacred script can read the file. My perl book doesn't cover Net:Telnet but I'll search the web for it. I thought a telnet-> file would be a commonly needed util.
Thanks
| [reply] |
#!/usr/bin/perl
use strict;
use warnings;
use Net::Telnet;
my $t = Net::Telnet->new(
Timeout => 10,
Port => 80
);
$t->open('www.google.com');
$t->print('GET /');
my $line = 0;
while (my $o = $t->getline())
{
print ++$line . '. ' .$o;
}
Instead of port 80, you'd use port 6666. Instead of www.google.com, you'd use the real server. Instead of printing GET /, you'd do whatever starts the flow of information (which may be nothing - if so, remove that line). Instead of printing the line inside the while loop to STDOUT (the default), you'd print to a filehandle that you opened prior to the while loop, and you'd flush the filehandle after each write. So, something like this, which, unlike the above, is untested:
#!/usr/bin/perl
use strict;
use warnings;
use Net::Telnet;
my $t = Net::Telnet->new(
Timeout => 10,
Port => 6666
);
$t->open('mydataserver') or die "Can't connect to mydataserver: $!";
open my $fh, '>', '/tmp/file' or die "Can't write to /tmp/file: $!";
$fh->autoflush(1);
while (my $o = $t->getline())
{
print $fh $o;
# or $fh->print($o);
}
close $fh;
| [reply] [d/l] [select] |