#!/bin/bash upsname="{{ upsname }}" retries=5 retry_delay=30 # Check dependencies which upsc >/dev/null || exit 1 upsstat=1 # just to bootstrap the loop while [ $upsstat -ne 0 ]; do upsc $upsname upsstat=$? if [ $upsstat -eq 1 ]; then let retries=retries-1 if [ $retries -le 0 ]; then /usr/sbin/shutdown -r now fi sleep $retry_delay fi done