I run my SME in server-only mode, and I wanted to keep a record of my WAN IP for various reasons.
I wrote a script that outputs the date, time and WAN IP either once each day or if the WAN IP changes.
Here's the script:
/usr/local/bin/wanip_log.sh:
#!/bin/bash
mylog=/var/log/wanip.log
mydate=$(date +"%F")
mywanip=$(dig +short myip.opendns.com @resolver1.opendns.com)
if [ -f $mylog ]; then
myoldip=$(tail -1 /var/log/wanip.log |cut -f3 -d' ')
mylastdate=$(tail -1 /var/log/wanip.log |cut -f1 -d' ')
else
touch $mylog
myoldip=a.b.c.d
mylastdate=1970-01-01
fi
if [ "$mywanip" == "$myoldip" ]; then
if [ "$mydate" != "$mylastdate" ]; then
echo $(date +"%F %T") $mywanip >> $mylog
fi
else
echo $(date +"%F %T") $mywanip >> $mylog
fi
And here's what i put into crontab:
*/5 * * * * /usr/local/bin/wanip_log.sh