hawihoney Posted December 4, 2009 Share Posted December 4, 2009 Is there a way to recognize a change of the WAN IP? I would like to call a script whenever this IP changes (to re-start nzbget for example): nzbget -q nzbget -s & Many thanks in advance. Harald Quote Link to comment
bubbaQ Posted December 5, 2009 Share Posted December 5, 2009 No, but you can do it easily: You can write a script that pulls your router config page with wget, parses it for the router's WAN IP address, and then take action if changed. Then put it in a loop with a sleep command or schedule it with cron. Quote Link to comment
yp_1 Posted December 5, 2009 Share Posted December 5, 2009 Is there a way to recognize a change of the WAN IP? I would like to call a script whenever this IP changes (to re-start nzbget for example): nzbget -q nzbget -s & Many thanks in advance. Harald For example (copy/paste the following into root user terminal session): SCRIPT=/boot/custom/bin/restart_on_ip_change.sh SCRIPT_DIR=`dirname $SCRIPT` [ -d "$SCRIPT_DIR" ] || mkdir -p $SCRIPT_DIR cp -p /boot/config/go /var/tmp cat >>/boot/config/go <<EOF # # Add nzbget restart to crontab # crontab -l >/tmp/crontab cp /tmp/crontab /var/spool/cron/crontabs/root- (echo -n '0 * * * * '; echo $SCRIPT) >>/tmp/crontab crontab /tmp/crontab EOF cat >$SCRIPT <<EOF #!/bin/bash IP_FILE="/var/tmp/current_ip" NEW_ADDR=\$(wget -O - http://ipdetect.dnspark.com/ 2>/dev/null | grep Address | tr -cd '0-9.') OLD_ADDR=\$(cat $IP_FILE) if [ "\$NEW_ADDR" != "\$OLD_ADDR" ]; then nzbget -q nzbget -s & fi echo \$NEW_ADDR >\$IP_FILE EOF Quote Link to comment
yp_1 Posted December 5, 2009 Share Posted December 5, 2009 Sorry, there was an error. Here is the correct code: SCRIPT=/boot/custom/bin/restart_on_ip_change.sh SCRIPT_DIR=`dirname $SCRIPT` [ -d "$SCRIPT_DIR" ] || mkdir -p $SCRIPT_DIR cp -p /boot/config/go /var/tmp cat >>/boot/config/go <<EOF # # Add nzbget restart to crontab # crontab -l >/tmp/crontab cp /tmp/crontab /var/spool/cron/crontabs/root- (echo -n '0 * * * * '; echo $SCRIPT) >>/tmp/crontab crontab /tmp/crontab EOF cat >$SCRIPT <<EOF #!/bin/bash IP_FILE="/var/tmp/current_ip" NEW_ADDR=\$(wget -O - http://ipdetect.dnspark.com/ 2>/dev/null | grep Address | tr -cd '0-9.') OLD_ADDR=\$(cat \$IP_FILE 2>/dev/null) if [ "\$NEW_ADDR" != "\$OLD_ADDR" ]; then nzbget -q nzbget -s & fi echo \$NEW_ADDR >\$IP_FILE EOF chmod +x $SCRIPT Quote Link to comment
hawihoney Posted December 6, 2009 Author Share Posted December 6, 2009 Thanks a lot guys. This helps a lot. Regards Harald Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.