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

35 lines
799 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");
my $event = $ARGV [0];
defined $ARGV[1] || die "No host specied";
my $host = $ARGV[1];
reboot_host($host);
exit 0;
sub reboot_host
{
my ($hostName) = @_;
#------------------------------------------------------------
# Reboot the host
#------------------------------------------------------------
my $h = $db_hosts->get($hostName) or die "No host record for user $hostName";
system("/usr/bin/sudo -u amgmt /usr/bin/ssh -o StrictHostKeyChecking=no amgmt\@$hostName /usr/bin/sudo /sbin/reboot") == 0
or die "Error rebooting $hostName";
}