init III
This commit is contained in:
130
Windows WakeOnLAN/WOL/WOL.pl
Normal file
130
Windows WakeOnLAN/WOL/WOL.pl
Normal file
@@ -0,0 +1,130 @@
|
||||
#!perl -w
|
||||
|
||||
package PerlSvc;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Net::Wake;
|
||||
|
||||
my $service = 'WOLawClient';
|
||||
my $servno = 0;
|
||||
my $logfile = 'c:/wol.log';
|
||||
my $configfile = 'c:/wol.conf';
|
||||
my $delay = 30;
|
||||
|
||||
my @options = ('log=s' => \$logfile,
|
||||
'config=s' => \$configfile,
|
||||
'service=s' => \$servno,
|
||||
);
|
||||
|
||||
# turn on autoflush
|
||||
$|=1;
|
||||
|
||||
(my $progname = $0) =~ s/.*?([^\\]+?)(\.\w+)$/$1/;
|
||||
our(%Config,$Verbose);
|
||||
|
||||
sub get_options {
|
||||
require Getopt::Long;
|
||||
my @options = @_;
|
||||
my $usage = pop @options;
|
||||
$SIG{__WARN__} = sub { print "$usage\n$_[0]"; exit 1 };
|
||||
Getopt::Long::GetOptions(@options);
|
||||
$SIG{__WARN__} = 'DEFAULT';
|
||||
}
|
||||
sub configure {
|
||||
%Config = (ServiceName => "WOLawClient$servno",
|
||||
DisplayName => "WOLawClient$servno",
|
||||
Parameters => "--log $logfile --config $configfile --service $servno",
|
||||
Description => "WakeOnLan Client");
|
||||
}
|
||||
sub Startup {
|
||||
get_options(@options, <<__USAGE__);
|
||||
Try `$progname --help` to get a list of valid options.
|
||||
__USAGE__
|
||||
|
||||
Log("\n$Config{DisplayName} starting at: ".localtime);
|
||||
my ($FILE)=@ARGV;
|
||||
open FH, "<$configfile";
|
||||
my @CONF=<FH>;
|
||||
close FH;
|
||||
while (ContinueRun($delay)) {
|
||||
foreach my $line (@CONF) {
|
||||
chomp;
|
||||
next if ($line =~ /^#/);
|
||||
my ($IP,$MAC,$PORT)=split / /,$line;
|
||||
Net::Wake::by_udp($IP,$MAC,$PORT);
|
||||
}
|
||||
}
|
||||
Log("$Config{DisplayName} stopped at: ".localtime);
|
||||
}
|
||||
sub Log {
|
||||
my $msg = shift;
|
||||
open(my $f, ">>$logfile") or die $!;
|
||||
print $f "$msg\n";
|
||||
close $f;
|
||||
}
|
||||
sub Install {
|
||||
#get_options('name=s' => \$service, @options, <<__USAGE__);
|
||||
get_options(@options, <<__INSTALL__);
|
||||
Valid --install suboptions are:
|
||||
|
||||
auto automatically start service
|
||||
--log log file name [$logfile]
|
||||
--config config file name [$configfile]
|
||||
--service service number [$servno]
|
||||
|
||||
For example:
|
||||
|
||||
$progname --install auto --log logfile --config configfile --service servicenumber
|
||||
|
||||
__INSTALL__
|
||||
|
||||
configure();
|
||||
}
|
||||
sub Help {
|
||||
print <<__HELP__;
|
||||
|
||||
Sends WakeOnLan Packets to MAC addresses defined in configfile
|
||||
|
||||
Install it as a service:
|
||||
|
||||
$progname --install auto --log logfile --config configfile --service servicenumber
|
||||
net start $service
|
||||
|
||||
You can pause and resume the service with:
|
||||
|
||||
net pause $service
|
||||
net continue $service
|
||||
|
||||
To remove the service from your system, stop und uninstall it:
|
||||
|
||||
net stop $service
|
||||
$progname --remove
|
||||
|
||||
servicenumber defaults to 0
|
||||
logfile defaults to c:\\wol.log
|
||||
configfile defaults to c:\\wol.conf
|
||||
__HELP__
|
||||
|
||||
# Don't display standard PerlSvc help text
|
||||
$Verbose = 0;
|
||||
}
|
||||
sub Pause {
|
||||
Log("$Config{ServiceName} is about to pause at ".localtime);
|
||||
}
|
||||
sub Continue {
|
||||
Log("$Config{ServiceName} is continuing at ".localtime);
|
||||
}
|
||||
sub Remove {
|
||||
get_options('service=s' => \$servno, <<__REMOVE__);
|
||||
Valid --remove suboptions are:
|
||||
|
||||
--service service number [$servno]
|
||||
|
||||
For example:
|
||||
|
||||
$progname --remove --service 0
|
||||
__REMOVE__
|
||||
$Config{ServiceName} = "$service$servno";
|
||||
$Config{DisplayName} = "$service$servno";
|
||||
}
|
||||
Reference in New Issue
Block a user