36 lines
854 B
Plaintext
36 lines
854 B
Plaintext
|
#!/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 specified";
|
||
|
my $host = $ARGV[1];
|
||
|
|
||
|
shutdown_host($host);
|
||
|
|
||
|
exit 0;
|
||
|
|
||
|
sub shutdown_host
|
||
|
{
|
||
|
my ($hostName) = @_;
|
||
|
#------------------------------------------------------------
|
||
|
# Shutdown the host
|
||
|
#------------------------------------------------------------
|
||
|
|
||
|
my $h = $db_hosts->get($hostName) or die "No host record for $hostName";
|
||
|
my $user = $h->prop('sshUser') || 'amgmt';
|
||
|
|
||
|
system("/usr/bin/sudo -u amgmt /usr/bin/ssh -o StrictHostKeyChecking=no $user\@$hostName /usr/bin/sudo /sbin/poweroff") == 0
|
||
|
or die "Error shutting down $hostName";
|
||
|
|
||
|
}
|