doraemon/root/etc/e-smith/events/actions/doraemon-wake

36 lines
783 B
Plaintext
Raw Normal View History

2016-07-27 23:10:06 +00:00
#!/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");
2017-10-08 17:41:59 +00:00
my $event = $ARGV[0];
2016-07-27 23:10:06 +00:00
2017-10-08 17:41:59 +00:00
defined $ARGV[1] || die "No host specified";
2016-07-27 23:10:06 +00:00
my $host = $ARGV[1];
wake_host($host);
exit 0;
sub wake_host
{
my ($hostName) = @_;
#------------------------------------------------------------
# Wake up the host
#------------------------------------------------------------
2017-10-08 17:41:59 +00:00
my $h = $db_hosts->get($hostName) or die "No host record for $hostName";
2016-07-27 23:10:06 +00:00
my $client = $h[0];
my $mac = $client->prop('MacAddress');
2017-10-08 17:42:51 +00:00
system("/sbin/ether-wake -b -i lan0 $mac") == 0
2016-07-27 23:10:06 +00:00
or die "Error waking up $hostName";
}