I posted my script too soon, when I ran it via cron it didn,t work
Only needed some minor tweaks!
Also added a function to send an email notifying the change.
| Code: |
nslookup some_domain.dyndns.org | tail -2 > ip.txt
IP=$(tail ip.txt)
OLDIP=$(tail oldip.txt)
if [ "$IP" = "$OLDIP" ];
then
echo no change
else
echo changed
/bin/asterisk.reload
#!/bin/bash
# script to send simple email
# email subject
SUBJECT="IP Change notification"
# Email To ?
EMAIL="someone@somewhere.com"
# Email text/message
EMAILMESSAGE="mail.txt"
echo $IP "from" > $EMAILMESSAGE
echo $OLDIP >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
tail ip.txt > oldip.txt
fi
|
Notes.
1/ this has only been tested by me disconnecting and reconnecting my router. But it did seem to resolve my sipgate issue.
2/ I run this as a cron job every 5 minutes so in theory the issue could be present for up to 5 minutes .
3/ It works for me I can't say if it will work for you, use at your own risk.
Steve