#!/bin/bash BAREOS_SD_IP=172.16.2.23 BAREOS_SD_PORT=9103 IPMI_IP=172.16.2.18 IPMI_USER=USER IPMI_PASS=PASSWORD SLEEP=5 NUM_TRIES=24 function check_bareos_sd { nc -w1 $BAREOS_SD_IP $BAREOS_SD_PORT < /dev/null 2>/dev/null if [ $? -eq 0 ]; then # if return value is 0 then port is reachable so we can exit the function with value 0 return 0 else return 1 fi } COUNT=0 while true; do check_bareos_sd if [ $? -eq 0 ]; then # We are online, so exit loop exit 0 else # We are offline, so add 1 to counter, sleep for $SLEEP seconds and continue loop # $COUNT=0 then we can power on the machine using ireset (ipmiutil) if [ $COUNT -eq 0 ]; then ireset -u -N $IPMI_IP -U $IPMI_USER -P $IPMI_PASS >/dev/null 2>&1 fi let COUNT=$COUNT+1 sleep $SLEEP fi # check if $COUNT reaches $NUM_TRIES and when it does exit with value 1 if [ $COUNT -eq $NUM_TRIES ]; then exit 1 fi done