#!/usr/bin/env perl use Net::Telnet; use IO::File; sub dump_file($$) { my ( $name, $guts ) = @_; my $fh = new IO::File ">" . $name; return unless defined $fh; $fh->print($guts); $fh->close; undef $fh; } my $timeout = 60; my $host = $ARGV[0]; my $path = "/var/run/boiler_" . $host; mkdir( $path, 0755 ); while (1) { my $telnet = new Net::Telnet( Timeout => 10, Telnetmode => 0, Binmode => 1, Host => $host, Port => 2001 ); #$telnet->open($bits[1]); my $nodata = 0; while ( ( not $telnet->eof ) and ( $nodata < $timeout ) ) { my $line = undef; eval { local $SIG{ALRM} = sub { die 'Timed Out'; }; alarm 2; $line = $telnet->getline( Timeout => 1, Errmode => 'return' ); alarm 0; }; alarm 0; if ( not defined $line or ( length($line) == 0 ) ) { $nodata++; next; } else { $nodata = 0; } chomp $line; chomp $line; $line = uc($line); next unless $line =~ /^([TB])(.)(.)(..)(....)/; my $fn = $1 . $2 . "x" . $4; my $c = $1 . $2 . $3 . $4 . $5; dump_file( $path . "/" . $fn, $c ); } $telnet->close; } exit(0);