Two suggestions…
- You could use a while loop to keep sleeping the script for 15s (or longer) until the backup server has booted.
- You could alternately use netcat to open a daemon on a specific port & listen for a connection from the backup server, though that would require a corresponding script on the backup server to execute at boot in order to complete the connection. Then you just have to wait until the backup server closes the connection to know it’s ready. (and if the backup server sends a zero-length packet to the port in question it’ll disconnect immediately).
The 2nd suggestion is cleaner, but really only works if there’s only one system that’s backing up to one system. You can kinda get around that by giving the boot script on the backup server multiple hosts to connect to via netcat, but up to you. 🙂
The 3rd semi-suggestion is to use rtcwake on the backup server to have it wake itself up at a specific time, if for some reason wakeonlan isn’t working
EDIT – adding the code for the while loop, just in case this works. change this section:
ping -c 1 dev3
#
# If ping fails ( ${?} is not 0 ) wait 15 seconds and try again
if [ ${?} -ne 0 ] ; then
echo "No connection after 30 seconds; waiting 15 more seconds."
sleep 15
ping -c 1 dev3
if [ ${?} -ne 0 ] ; then
#
# If still no connection, give up.
echo "No connection after 45 seconds; terminating backup attempt."
echo "Backup failed $( date +%Y%m%d\ %H%M ) " >> /root/statuslog.txt
exit
fi
fi
to this:
counter=0
maxcounter=5
sleeptimer=15
ping -c 1 dev3
[[ $? -eq 0 ]] && counter=$maxcounter
while [ $counter -lt $maxcounter ]
do
sleep $sleeptimer
ping -c 1 dev3
[[ $? -eq 0 ]] && counter=$maxcounter || counter=$counter+1
done
ping -c 1 dev3
if [ $? -ne 0 ]; then
echo "No connection after $((${maxcounter}*${sleeptimer})) seconds; terminating backup attempt."
echo "Backup failed $( date +%Y%m%d\ %H%M ) " >> /root/statuslog.txt
exit
fi