[Task description]
We have a dns record domain.com it can resolve to IP1 or IP2. We don't know which one exactly (GTM load balancing)
The script will check every 5 minutes if the IP address for domain.com has changed. If it has than it will execute restartprogram1.sh if it hasn't do nothing.
[End of task description/]
I was thinking maybe to set both IPs as variable but it will work only in one direction
Than I was thinking to store the IP in file and use this file to check if the IP has changed every 5 mins.
Code:
#!/bin/bash
set -x
# domain.com can resolve to 100.24.34.4 or 100.24.35.4
now=`/usr/sbin/nslookup domain.com | /usr/bin/grep 100 | cut -d" " -f2`
before=`cat /home/scripts/lookup`
if [ now =! before ] || [ -z `$before`] then
`/usr/sbin/restartprogram.sh`
echo $now > lookup`
else
`/usr/sbin/restartprogram.sh`
echo $now > lookup
fi
#END
I'm learning and will appreciate every helpful feedback and idea
Cheeerss