Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jul 13th, 2005, 9:33 PM   #1
sonson
Newbie
 
Join Date: Jun 2005
Posts: 8
Rep Power: 0 sonson is on a distinguished road
Recoonect...

Well i have a full working script that connects to a port and writes logs to a file continuosly one problem with it tho is that when the machine breaks down for couple of hours or minutes it is ssupposed to connect back up to the server but it does not and i miss out on all the logs...
any one has a simple script for doing that...so that when it notice the connection breaks it connects automatically aagain...
thnks in advance...

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;
sonson is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:04 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC