Thread: Recoonect...
View Single Post
Old Jul 13th, 2005, 11:04 PM   #3
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
w/code tags

use strict;
use Socket;

# initialize host and port
my $host = shift || '172.16.10.30';
my $hosts = "/etc/hosts/";

print STDERR "Enter hostname: ";
$host = <STDIN>;
chomp($host);

open (NUMBERS, "/etc/hosts/");

while ($hosts = <NUMBERS>) {
     print $hosts;
  }

close(NUMBERS);



my $port = shift || 5221;

my $proto = getprotobyname('tcp');

# get the port address
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);

# create the socket, connect to the port
socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; connect(SOCKET
, $paddr) or die "connect: $!";



my @t = localtime(time);

my $fileTimeStamp = ($t[5]+1900) . "-" . ($t[4]+1) . "-" . $t[3];

open(OUTPUT_FILE, ">>/data2/elsonba/zizo/" . $fileTimeStamp . ".log");

select OUTPUT_FILE; $| = 1;

my $line;

while (<SOCKET>)
{
     my @ct = localtime(time()); # current localtime

     my $currentTimeStamp = ($t[5]+1900) . "-" . ($t[4]+1) . "-" . $t[3];
     
     if($fileTimeStamp ne $currentTimeStamp)
     
     {
           $fileTimeStamp = $currentTimeStamp; # set file stamp to current for use in open and later checks
           close OUTPUT_FILE || warn($!);
           open(OUTPUT_FILE,">>/data2/elsonba/zizo/" . $fileTimeStamp . ".OMlog") || die($!);
     }

     print OUTPUT_FILE "$_\n";
}
close SOCKET or die "close: $!";

close OUTPUT_FILE;
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote