package PerlSvc; use strict; use warnings; use IO::Socket; use Time::HiRes qw( sleep ); use Data::Dumper; use TextLogger; use Helpers; # the short name by which your service will be known (cannot be 'my') our $Name = "pmtimeclnt"; # the display name. This is the name that the Windows Control Panel # will display (cannot be 'my') our $DisplayName = "PerlMonks Time Client"; # the startup routine is called when the service starts sub Startup { my $waitcount = 300; # <- Wait 30 seconds at startup for things to settle down... my $logfilename = 'C:\Programme\PerlMonks\TimeClient.log'; my $logger = new TextLogger(logfile => $logfilename, appname => 'TimeClient'); my $alivecount = 36000; while (ContinueRun()) { $alivecount--; if(!$alivecount) { $alivecount = 36000; $logger->alive(); } $waitcount--; if(!$waitcount) { $logger->log("Start of syncronize cycle"); my $socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1", PeerPort => 64100, Proto => "tcp", Type => SOCK_STREAM); if(!$socket) { #print "Socket error...\n"; $waitcount = 600; #try again in a minute $logger->log("Socket error"); } else { foreach my $line (<$socket>) { $logger->log("Parsing reply..."); if($line =~ /(\d\d-\d\d-\d\d\d\d)\ (\d\d\:\d\d\:\d\d)/) { my ($dstamp, $tstamp) = ($1, $2); system("cmd.exe /c date $dstamp"); system("cmd.exe /c time $tstamp"); $logger->log("SET: Date = $dstamp / Time = $tstamp"); } } close $socket; $waitcount=36000; # wait an hour } } sleep(0.1); } $logger->log("For great justice!"); #AYBABTU!!1! } sub Install { # add your additional install messages or functions here print "The $Name Service has been installed.\n"; print "Start the service with the command: net start $Name\n"; } sub Remove { # add your additional remove messages or functions here print "The $Name Service has been removed.\n"; } sub Help { # add your additional help messages or functions here print "$Name Service -- add custom help message here.\n"; } sub Interactive { Startup(); }