#!/bin/bash cd /scripts # Time in minutes between polls TIMER=60 LASTIPFILE=lastipfile.dat COUNTFILE=lastipindex.dat if [ -f $LASTIPFILE -a -r $LASTIPFILE ]; then LASTIP=`cat $LASTIPFILE` fi COUNT=`cat $COUNTFILE` if [ -z "$COUNT" ]; then COUNT=0; fi while :; do COUNT=`expr $COUNT + 1` TOTAL=`cat iplist | grep -v ^# | grep -v "^ *$" | wc -l` if [ $COUNT -gt $TOTAL ]; then COUNT=1; fi echo $COUNT > $COUNTFILE CURRENTURL=`cat iplist | grep -v ^# | grep -v "^ *$" | sed --silent -e ${COUNT}p` echo $CURRENTURL >&2 MYIP=`wget $CURRENTURL -O - 2>/dev/null \ | grep [0-9] \ | sed \ -e 's/[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/\n&\n/g' \ | grep '^[0-9]\.\|^[0-9][0-9]\.\|^[0-9][0-9][0-9]\.' \ | grep '^[0-9][0-9]*\.[0-9]\.\|^[0-9][0-9]*\.[0-9][0-9]\.\|^[0-9][0-9]*\.[0-9][0-9][0-9]\.' \ | grep '^[0-9][0-9]*\.[0-9][0-9]*\.[0-9]\.\|^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]\.\|^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9][0-9]\.' \ | grep '^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9]$\|^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]$\|^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9][0-9]$' \ | sed \ -e 's/\./ /g' \ | while read ONE TWO THREE FOUR FIVE; do if [ -n "$FIVE" -o -z "$FOUR" ]; then continue; fi if [ $ONE -gt 255 ]; then continue; fi if [ $TWO -gt 255 ]; then continue; fi if [ $THREE -gt 255 ]; then continue; fi if [ $FOUR -gt 255 ]; then continue; fi echo $ONE.$TWO.$THREE.$FOUR break done` if [ -z "$MYIP" ]; then echo FAIL | mail -s "FAILURE TO GET MY IP" root; echo Failed to get current IP; fi if [ "$LASTIP" != "$MYIP" ]; then echo IP Address change from [$LASTIP] to [$MYIP] LASTIP=$MYIP echo $LASTIP > $LASTIPFILE cp $LASTIPFILE homebox.txt tar -cf - homebox.txt | ssh user@mydomain.com "(cd public_html && tar -xvf -)" else echo No change, IP is [$MYIP] fi echo Sleeping $TIMER minutes sleep `expr 60 \* $TIMER` done