From Nuclear Physics Group Documentation Pages
Jump to navigationJump to search

This script is located in /etc/apcupsd/shutdown2 on gourd. It monitors battery life and shuts down other systems connected to the UPS as battery life is depleted.

  1. !/bin/sh

while [ 1 ]; do

 if [ `/usr/sbin/apcaccess | grep STATUS | awk '{print $3}'` = "ONLINE" ] ; then
   echo "online, exiting"| write Tbow
   exit 0
 CHARGE=`/usr/sbin/apcaccess | grep BCHARGE | awk '{print $3}'`
 echo "monitoring charge" | write Tbow
 if [ `echo "$CHARGE <= 50.0" | bc` -eq 1 ]; then
   wall "apcupsd: Shutting down machines in rack."
    ssh -i /root/.ssh/shutdown_id_rsa root@taro 'shutdown -h now'
    sleep 5
    ssh -i /root/.ssh/shutdown_id_rsa root@pumpkin 'shutdown -h now'
    sleep 5
    ssh -i /root/.ssh/shutdown_id_rsa root@tomato 'shutdown -h now'
    sleep 5
    ssh -i /root/.ssh/shutdown_id_rsa root@roentgen 'shutdown -h now'
 if [ `echo "$CHARGE <= 5.0" | bc` -eq 1 ]; then
   wall "apcupsd: Shutting down Einstein and Jalapeno"
    ssh -i /root/.ssh/shutdown_id_rsa root@einstein 'shutdown -h now'
    sleep 5
    ssh -i /root/.ssh/shutdown_id_rsa root@jalapeno 'shutdown -h now'
   exit 1
 sleep 30