#!/usr/bin/perl -w use strict; use IO::Socket; use MIME::Lite; use Time::Out qw(timeout); use IO::Handle; $SIG{PIPE} = "IGNORE"; $| = 1; my $nb_secs = 10; my $buf = ""; my $file; umask 002; my $sock = new IO::Socket::INET (PeerAddr => '192.168.173.9', PeerPort => 7001, Proto => 'tcp', Type => SOCK_STREAM, ); die "cannot open socket" unless ($sock); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); my $hrmin = sprintf ("%02d%02d",$hour,$min); my $ymd = sprintf("%04d%02d%02d%02d%02d%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec); my $filename = "/var/flexshare/shares/logs/backup.$ymd.txt"; open $file, ">$filename" || die("Couldn't open $file"); $file->autoflush(1); my $login = "&NE014\r\n"; my $pass = "house\r\n"; my $dump = "P H 19\r\n"; my $logout = "&NG\r\n"; my $enter = "\r\n"; print $sock $enter; print $sock $enter; # if (<$sock> =~ m/^(R> )/) { # print $sock $dump; # } else { # print $sock $logout; # print $sock $login; # print $sock $pass; # } print $sock $dump; while (my $line = <$sock>) { timeout $nb_secs => sub { my $count = 0; until ($count == 5 ) #Read the next xx lines { print $file $line; $sock->flush(); $count++; } }; if ($@){ $line = ""; } } close $file; close $sock;