From 61124dd1c6587f86c05cb4964599fa4c3918cba2 Mon Sep 17 00:00:00 2001 From: hjp Date: Mon, 26 Sep 2011 10:09:03 +0000 Subject: [PATCH] Simple script to check upscheck and shut down server if necessary. --- upscheck/upscheck | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 upscheck/upscheck diff --git a/upscheck/upscheck b/upscheck/upscheck new file mode 100644 index 0000000..8890ffc --- /dev/null +++ b/upscheck/upscheck @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use LWP::Simple; + +my %ups; +my $content = get("http://intra.wsr.ac.at/informationssysteme/ups/"); +for my $line (split(/\n/, $content)) { + my ($oid, $value) = split(/\t/, $line); + $ups{$oid} = $value; +} + +if (!defined $ups{'UPS-MIB::upsEstimatedMinutesRemaining.0'} || + !defined $ups{'UPS-MIB::upsEstimatedChargeRemaining.0'} +) { + die "can't get current charge"; +} + +my $min_minutes = rand(10) + 5; +my $min_charge = rand(10) + 5; + +if ($ups{'UPS-MIB::upsEstimatedMinutesRemaining.0'} < $min_minutes || + $ups{'UPS-MIB::upsEstimatedChargeRemaining.0'} < $min_charge +) { + print STDERR "charge low: shutting down\n"; + system("/sbin/shutdown", "-h", "+1"); +}