doraemon/root/etc/e-smith/events/actions/doraemon-wake
2016-07-28 01:10:06 +02:00

36 lines
784 B
Perl
Executable File

#!/usr/bin/perl -w
package esmith;
use strict;
use Errno;
use esmith::DB::db;
use IO::File;
use English;
my $db_hosts = esmith::DB::db->open('hosts') || die("Could not open e-smith db (" . esmith::DB::db->error . ")\n");
my $event = $ARGV [0];
defined $ARGV[1] || die "No host specied";
my $host = $ARGV[1];
wake_host($host);
exit 0;
sub wake_host
{
my ($hostName) = @_;
#------------------------------------------------------------
# Wake up the host
#------------------------------------------------------------
my $h = $db_hosts->get($hostName) or die "No host record for user $hostName";
my $client = $h[0];
my $mac = $client->prop('MacAddress');
system("/sbin/ether-wake -i lan0 $mac") == 0
or die "Error waking up $hostName";
}