PDA

View Full Version : Auto DNS update script


ciper
11-15-2006, 06:18 AM
New version as of 13 August 2007

Before coming down with a serious illness I created a working copy of a script that will automatically update a DNS name for your Tivo.

I thought it was a shame for it to goto waste so Ill share it with everyone.

This was created on a S1 Sony but should be able to work with any Tivo assuming the required binaries are present.

ciper
11-15-2006, 06:23 AM
Prerequisites:
This script uses Netcat, cut and grep. Your machine should be able to resolve DNS requests through netcat. A browser able to send authentication is needed for initial setup. Dont forget to create your DYNDNS account. http://www.dyndns.com

Output:
The script will regularly tell you whats happening, for example what the current IP address is and if its change and the number of times it has run since last updating your domain. If you run the script from your rc.sysinit.author then the output will be stored in the kernel log. For example
Aug 14 04:12:51 (none) kernel: External IP has not changed from 1.2.3.4
Aug 14 04:12:51 (none) kernel: autodnsupdate has run 5 times since last update

Three files will be created:
/var/log/autodnsupdate.log will contain the output from the dyndns website when updating the IP address
/var/log/external_ip will contain the current external IP address (current as of last time the script ran)
/var/log/ipruns will contain the number of times the script has ran since last updating the website

Configuration:
Update - There is now an easier way to create your masked password.
Use this website http://www.motobit.com/util/base64-decoder-encoder.asp and enter your details as "myusername:mypassword" and press "convert source data" to generate the string. Modify the AUTH line in the script with a the characters in the second box. The DOMAIN line should be modified to match the dynamic dns host you created on DYNDNS.


The first step is to create your masked password. Configure netcat to listen for incoming connections then instruct wget to send an authorization request.

bash-2.02 nc -l -p 81 &
-Tells netcat to listen on port 81 and run in the background
[1] 739
bash-2.02 wget -q http://myusername:mypassword@127.0.0.1:81
- wget will connect to netcat and send the user/pass specified
GET / HTTP/1.0
User-Agent: Wget/1.8.2
Host: 127.0.0.1:81
Accept: */*
Connection: Keep-Alive
Authorization: Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk
- Hit ctrl-c to break out of wget
[1]+ Done nc -l -p 81
- netcat should exit as well

Modify the AUTH line below with a the characters after "Authorization: Basic" not including the space. The DOMAIN line should be modified to match the dynamic dns host you created on DYNDNS.

Contents:

#Autodnsupdate script created by ciper (at) hotmail (dot) com
#What the script does:
#The script will check your current external IP once every half hour. If it has
#changed the dyndns information is updated then it goes to sleep. If the IP
#hasnt changed the script goes to sleep again. If the IP address hasnt changed
#for 24 hours it connects to DYNDNS anyways to prevent your account deletion.

#Prerequisites:
#This script uses Netcat, cut and grep. Your machine should be able to resolve
#DNS requests through netcat. Wget or a browser able to send authentication is
#needed for initial setup. Dont forget to create your DYNDNS account.
#https://www.dyndns.com/services/dns/dyndns/
#Optionally you can disable the looping and use cron by removing the pound
#sign from the line "# LOOP=$(($LOOP-1))" and commenting out the sleep
#command near the end of the file

#Configuration:
#The first step is to create your masked password. Configure netcat to listen
#for an incoming connection then instruct an application to send the
#authentication request. Do this on your PC or Tivo. Ill use wget on Tivo.

#bash-2.02# nc -l -p 81 &
#-Tells netcat to listen on port 81 and run in the background
#[1] 739
#bash-2.02# wget -q http://myusername:mypassword@127.0.0.1:81
#- wget will connect to netcat and send the user/pass specified
#GET / HTTP/1.0
#User-Agent: Wget/1.8.2
#Host: 127.0.0.1:81
#Accept: */*
#Connection: Keep-Alive
#Authorization: Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk
#- Hit ctrl-c to break out of wget
#[1]+ Done nc -l -p 81
#- netcat exited as well

#Modify the AUTH line with a the characters after "Authorization: Basic" not
#including the space. The DOMAIN line should be modified to match the dynamic
#dns host you created on DYNDNS.

DOMAIN="something.dyndns.com"
AUTH="bXl1c2VybmFtZTpteXBhc3N3b3Jk"
LOOP=1

[ -f /var/log/ipruns ] || echo 0 >/var/log/ipruns

IPRUNS="`cat /var/log/ipruns`"
while [ "$LOOP" = "1" ]
do

OIP="`cat /var/log/external_ip`"
echo -e "GET / HTTP/1.1\n" | nc -w 3 checkip.dyndns.org 8245 | grep Address | cut -d "<" -f7 | cut -c 25- > /var/log/external_ip
CIP="`cat /var/log/external_ip`"

if [ "$OIP" != "$CIP" ] ; then
echo "External IP changed from $OIP to $CIP"
echo -e "GET /nic/update?hostname=$DOMAIN HTTP/1.1\nHost: members.dyndns.org:8245\nUser-Agent: Tivo\nAccept: */*\nAuthorization: Basic $AUTH\n" | nc -w 3 members.dyndns.org 8245 > /var/log/autodnsupdate.log
IPRUNS=0
else
echo "External IP has not changed from $CIP"
if [ "$IPRUNS" = "48" ] ; then
echo -e "GET /nic/update?hostname=$DOMAIN HTTP/1.1\nHost: members.dyndns.org:8245\nUser-Agent: Tivo\nAccept: */*\nAuthorization: Basic $AUTH\n" | nc -w 3 members.dyndns.org 8245 > /var/log/autodnsupdate.log
IPRUNS=0
echo "External IP has not been updated after running script 48 times, updating $DOMAIN anyways"
fi

fi

echo "autodnsupdate has run $IPRUNS times since last update"
IPRUNS=$(($IPRUNS+1))
echo "$IPRUNS" > /var/log/ipruns

#Remove pound sign from next line and add one in front of sleep command if
#you are using cron to run this script
#LOOP=$(($LOOP-1))
sleep 1800

done
echo "autodnsupdate exiting"

Verifying correct function
During your testing you should disable the looping feature of the script by following the instructions for cron setup. If you o not do this and you run the script backgrounded you could end up with a script that is very hard to stop from running (not necessarily a bad thing but a pain in the ass).

Check the file /var/log/external_ip for the correct external IP address. If it does not contain your ip address please verify the following command works
echo -e "GET / HTTP/1.1\n" | nc -w 3 checkip.dyndns.org 8245

The file /var/log/autodnsupdate.log should contain the status of the last update. Specifically the information after "Transfer-Encoding: chunked" is what you want to look at. For example my IP address has not changed for weeks so my file looks like (x.x.x.x was my IP)
HTTP/1.1 200 OK
Date: Tue, 14 Aug 2007 18:43:58 GMT
Server: Apache
X-UpdateCode: n
Content-Type: text/plain
Connection: close
Transfer-Encoding: chunked

10
nochg x.x.x.x
0
When your IP address does change the file will be slightly different:

HTTP/1.1 200 OK
Date: Tue, 14 Aug 2007 18:43:58 GMT
Server: Apache
X-UpdateCode: n
Content-Type: text/plain
Connection: close
Transfer-Encoding: chunked

10
good x.x.x.x
0
If you plan to run this using rc.sysinit.author make sure to reenable looping mode and place it after your other hacks. One bonus to running it this way is that status messages will automatically be stored in your kernel log. :)

Common problems:
Some Tivos will not allow loopback connections between wget and netcat. If that is the case run netcat on your PC with the same command line and then wget on your Tivo with the same command line but replace 127.0.0.1 with your PC IP address. You can find Netcat for windows here http://www.vulnwatch.org/netcat/

Do not forget the quotes around your domain and the authorization string. The top of your script should resemble something like
DOMAIN="something.dyndns.com"
AUTH="bXl1c2VybmFtZTpteXBhc3N3b3Jk"
LOOP=1

ciper
11-15-2006, 06:28 AM
For those interested in my authentication method,
I used WGET/NETCAT because I didnt like usernames and passwords hard coded into the script in clear text.

My intention for this script originally was to enable Sling Box type functionality on my Tivo. I still plan to do this but I have alot of reading to do - I forgot alot of my Tivo knowledge during my time away from the forums!

ciper
02-20-2007, 09:09 PM
One note. While testing this program be careful not to lock your DynDNS account. I had mine set in an automatic loop one day and after an hour or so my account was suspended :)
If you suspect your account has been locked check your registered Email for instructions on how to clear it.

AMc UK
08-13-2007, 12:35 PM
Hey ciper - I got here from your comment in UK TC "Clever Little Gizmo" thread.
My ISP likes to change my IP more often than I change underwear and I don't leave a PC on 24/7 so I need an alternative to get external TivoWeb Access.

I appreciate this is a development forum not a "support" or "ask a dumb newbie question" forum - but I'm hoping you can point me where to find the netcat binary esp. without installing a bunch of other stuff I don't need?

Cut and grep are already there.

ciper
08-13-2007, 05:18 PM
Ill try to locate the file for you. If I recall correctly it was posted on one of the Tivo Australia message boards and was part of a package that included about 10 DNS capable network tools. The archive had the word libresolv in the name. Realize the netcat binary is called "nc"

Edit: I found the file on my computer and its called libresolv-0.1-bins.tar.gz

There is another set of DNS enabled tools that I used the first time I created this script but I cannot remember the name. There are a huge number of non DNS aware binaries posted in different places that won't work with this script.
I planned to test this script with the libresolv-0.1-bins.tar.gz version of netcat but I am having trouble with resolution at the moment.

edit2: Feck hell shit. I had two copies of NC on my Tivo and the one I was running was the non DNS aware version. If you see the error "error in loading shared libraries: undefined symbol: gethostbyname" then most likely you have a non working DNS version of the binary. Something new I just found may be of interest. From this site http://www.tuhs.org/twiki/bin/view/FAQ/ProblemsAndSolutions
if you have a proxy server on your network, you can type "export http_proxy=http://ipaddress:port/"
where ipaddress is the ipaddress of your proxy server, and port is the port it runs on (eg squid's
default port is 3128), this way the DNS resolution is done by the proxy server, so tivo doesn't need
to be able to do DNS resolution. Or try entering a valid namserver in /etc/resolve.conf, first make the
filesystem writeable with rw, then ro when done
I have not tested either of these methods.

edit3: DynDNS has completely change their website. I have tested and modified the script and it works as of 13 August 2007. https://www.dyndns.com/services/dns/dyndns/

AMc UK
08-14-2007, 10:48 AM
Found that file with nc in it at http://minnie.tuhs.org/TiVo/files/libresolv/libresolv-0.1-bins.tar.gz
and after a lot of inept fiddling got it installed and wget and nc appear to be working but can't find each other?

If I run both commands on the same Tivo in seperate Telnet sessions (without backgrounding and verbose on) I can see wget "connecting to xxx.xxx.xx.xx:81" but it never makes a connection. NC just listens.

I can get wget to connect and login to my router so I know it's capable of sending the username and password in that HTTP syntax.

Then I had a bash at talking to nc with IE (as that's what's installed on here). It seems that MS removed the http username/password in the URL capability a long time ago. So I ran a registry hack to enable it. Again I'm able to connect through to my router so its working. And I can connect through to nc on tivo but nc/IE mask the authorisation header so it isn't visible in the telnet output of NC. I get all the other HTTP headers you'd expect which is really frustrating.

I can't get wget to connect to the Tivo it's running on, even accessing :80 to try and establish an unathenticated connection times out
bash-2.02# wget http://XXX.XXX.XX.XX
--13:32:03-- http://XXX.XXX.XX.XX/
=> `index.html.2'
Connecting to XXX.XXX.XX.XX:80... failed: Connection timed out.
Retrying.

--13:35:12-- http://XXX.XXX.XX.XX/
(try: 2) => `index.html.2'
Connecting to XXX.XXX.XX.XX:80... failed: Connection timed out.
Retrying.

I appreciate this is in no way your problem but until I can get that Authorisation token I can't install the script :(

Any suggestions :) ?

AMc UK
08-14-2007, 10:58 AM
Update: at least after a great deal of fiddling I managed to get wget to resolve outside my network by editing /etc/resolv.conf and putting my router's IP as the first nameserver.
nameserver xxx.xxx.xx.x
search engr.teleworld.com
nameserver 192.168.14.1
nameserver 192.168.14.2
So that version of wget I lined to does appear to resolve DNS on the Tivo or via my Buffalo Router.

ciper
08-15-2007, 02:09 AM
Hmm. At first I thought the issue was that you were using the external IP address of the Tivo when connecting with wget instead of the loopback address of 127.0.0.1 but I tried the way you did and got the following (x is for the real address)

bash-2.02# nc -l -p 81 &
[1] 367
bash-2.02#
bash-2.02# wget -q http://myusername:mypassword@x.x.x.x:81
GET / HTTP/1.0
User-Agent: Wget/1.8.2
Host: x.x.x.x:81
Accept: */*
Connection: Keep-Alive
Authorization: Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk

So I thought I would try the double telnet method and got
bash-2.02# nc -l -p 81
GET / HTTP/1.0
User-Agent: Wget/1.8.2
Host: x.x.x.x:81
Accept: */*
Connection: Keep-Alive
Authorization: Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk

[1]+ Done nc -l -p 81

So I then tried using the browser on my laptop. You are right that IE7 doesnt work! Firefox however did connect but it didn't display the authorization key because I didnt send an authentication request
bash-2.02# nc -l -p 81
GET / HTTP/1.1
Host: x.x.x.x:81
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20
070725 Firefox/2.0.0.6
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plai
n;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

I thought I'd try the Links web browser running on my tivo. Similar problem to firefox since I never sent a username/password request
bash-2.02# nc -l -p 81
GET / HTTP/1.1
Host: 127.0.0.1:81
User-Agent: Links (1.00pre13-no-ssl; Linux 2.1.24-TiVo-2.5 ppc; 80x60)
Accept: */*
Accept-Charset: us-ascii, ISO-8859-1, ISO-8859-2, ISO-8859-4, ISO-8895-5, ISO-88
59-7, ISO-8895-9, ISO-8859-13, ISO-8859-15, ISO-8859-16, windows-1250, windows-1
251, windows-1257, cp437, cp737, cp850, cp852, cp866, x-cp866-u, x-mac, x-mac-ce
, x-kam-cs, koi8-r, koi8-u, TCVN-5712, VISCII, utf-8
Accept-Language: en, en;q=0.2, *;q=0.1
Connection: Keep-Alive

Do you have TivoWebPlus running? If so can wget connect to it using the address 127.0.0.1 ?

AMc UK
08-15-2007, 06:21 AM
I'm running TivoWeb (not TivoWebPlus) on port 80 - the 'code' chunk in post #7 shows what happens - wget fails with a connection timeout after about 3 minutes and retries forever.

I know wget is working and resolving DNS (see this chunk below)
bash-2.02# wget http://www.google.com
--09:22:11-- http://www.google.com/
=> `index.html'
Resolving www.google.com... done.
Connecting to www.google.com[64.233.183.103]:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.co.uk/ [following]
--09:22:12-- http://www.google.co.uk/
=> `index.html'
Resolving www.google.co.uk... done.
Connecting to www.google.co.uk[64.233.183.103]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

[ <=> ] 3,308 0.00B/s

09:22:12 (0.00 GB/s) - `index.html' saved [3308]


I tried nc listening to IE on 443 to see if IE would 'special case' that port but no dice.

I also tried sending the same username/password combination from my Vodaphone Sony Ericsson K800 phone which rejected the URL as invalid :(
It did connect through to nc without the username/password. (See this chunk below)
bash-2.02# nc -v -v -l -p 443
listening on [any] 443 ...
[my current external IP]: inverse host lookup failed:
connect to [my tivo's internal IP] from (UNKNOWN) [my current external IP] 46837
GET / HTTP/1.0
Host: mydyndnsname.gotdns.com:the port I forwarded
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 MG (Novarra-Vision/6.1)
Accept: text/html;q=1.0, text/css; q=1.0, application/x-javascript; q=1.0, text/plain;q=0.8, application/xhtml+xml;q=0.6, application/x-httpd-php;q=0.1, */*;q=0, image/gif; q=1.0, image/jpeg; q=1.0, image/png; q=1.0
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Language: en
Accept-Encoding: identity;q=1.0, gzip;q=0.1, *;q=0
x-novarra-device-type: 0
x-Device-User-Agent: SonyEricssonK800iv/R1ED Browser/NetFront/3.3 Profile/MIDP-2
.0 Configuration/CLDC-1.1
x-Mobile-Gateway: Novarra-Vision/6.1 (VF-UK; Server-Only)
Via: HTTP/1.1 glgwsl22 (XMG 724Solutions HTG XMG-31_VODAFONE_M3_B030 20070724.091400), 1.1 Novarra (Vision/6.1), 1.1 frankenstein2:3128 (squid/2.6.STABLE9-20070214)
Cache-Control: max-age=259200
Connection: keep-alive

sent 0, rcvd 918

So tantilisingly
- I know that the DynDNS is working OK.
- I know that my port forwarding is working OK.
- I know nc is listening interally and externally
- I even accessed my Tivoweb on my phone by changing the port forward back to where it should go to point at Tivoweb....
- But I can't get that dratted Authorization: Basic string to set up the scripted check ....gggggrgrrrrrrrr!

I can only assume I have different version of wget and it doesn't like sharing a port with nc listening?

Thanks again for taking the time. Not sure what to try next TBH - any thoughts?

AMc UK
08-15-2007, 06:34 AM
FWIW this is the version of wget I'm using
bash-2.02# wget --help
GNU Wget 1.8.2, a non-interactive network retriever.
Usage: wget [OPTION]... [URL]...

This is the version of nc I'm using
bash-2.02# nc -help
[v1.10]

ciper
08-15-2007, 06:43 AM
So am I!

bash-2.02# wget --help
GNU Wget 1.8.2, a non-interactive network retriever.
nc
bash-2.02# nc -help
[v1.10]

From your above testing it seems to me that for some reason WGET doesnt like to loopback on itself on the tivo. Can't figure out why that would be?! Let me think about this...

Want to join me on the efnet tivo irc channel?

AMc UK
08-17-2007, 08:56 AM
Hey ciper - a massive thanks for the chat help on Wednesday.
To summarise - I was able with ciper's help to get the Authorisation string using netcat on windows and wget from my Tivo (as my Tivo resolutely refused to talk to itself). nc and wget can resolve DNS and so my Tivo can talk to the outside world. The script did what it should do from the command line :) and correctly updated a false IP set in my DynDNS account.

Note: when testing this stuff be careful to run autodnsupdate with the cron line uncommented and the sleep line commented. If you background it with a & you can end up with several sleeping scripts that you can kill but spring back to life over and over :eek:!

So with everything apparently working I added a line to "/etc/rc.d/rc.sysinit.author" to call it on start up.
rc.sysinit.author

#!/bin/bash
/var/hack/tivoweb-tcl/tivoweb
/var/hack/endpad.tcl -s 1 -e 6 -sugqual 75 -sugeq -auto >> /dev/null &
/var/hack/bin/cron &
/var/hack/scripts/autodnsupdate &
Unfortunately this caused errors on start up.
From the Kernel log...
Aug 15 12:30:22 (none) kernel: cat: /var/log/external_ip: No such file or directory
Aug 15 12:30:23 (none) kernel: /var/hack/scripts/autodnsupdate: nc: command not found
Aug 15 12:30:23 (none) kernel: /var/hack/scripts/autodnsupdate: /var/hack/scripts/autodnsupdate: cut: command not found
Aug 15 12:30:23 (none) kernel: cut: command not found
Aug 15 12:30:23 (none) kernel: /var/hack/scripts/autodnsupdate: line 82: 123 Broken pipe echo -e "GET / HTTP/1.1\n"
Aug 15 12:30:23 (none) kernel: 124 Exit 127 | nc -w 3 checkip.dyndns.org 8245
Aug 15 12:30:23 (none) kernel: 125 Exit 1 | grep Address
Aug 15 12:30:23 (none) kernel: 126 Exit 127 | cut -d "<" -f7
Aug 15 12:30:23 (none) kernel: 127 Exit 127 | cut -c 25- >/var/log/external_ip
Aug 15 12:30:24 (none) kernel: External IP has not changed from
Aug 15 12:30:24 (none) kernel: autodnsupdate has run 0 times since last update
Aug 15 12:30:25 (none) kernel: turbonet2: link = 100Mbps full-duplex

I had to go away and so the script ran every 30 minutes for a couple of days each time logging these errors in the Kernel Log and not updating anything into "external_ip" :(.

Aug 17 01:30:24 (none) kernel: tcp_keepalive: call keepopen(0x803c3bc0)
Aug 17 01:31:07 (none) kernel: /var/hack/scripts/autodnsupdate: /var/hack/scripts/autodnsupdate: /var/hack/scripts/autodnsupdate: nc: command not found
Aug 17 01:31:07 (none) kernel: cut: command not found
Aug 17 01:31:07 (none) kernel: cut: command not found
Aug 17 01:31:08 (none) kernel: External IP has not changed from
Aug 17 01:31:08 (none) kernel: autodnsupdate has run 26 times since last update
Aug 17 01:31:39 (none) kernel: tcp_keepalive: call keepopen(0x803c3bc0)


Today I tried adding the full path to "nc" and "cut" commands in the script
e.g.
echo -e "GET / HTTP/1.1\n" | /var/hack/bin/nc -w 3 checkip.dyndns.org 8245 | grep Address | /var/hack/bin/cut -d "<" -f7 | /var/hack/bin/cut -c 25- > /var/log/external_ip
And then because my linus knowledge is barely measurable I tried
echo -e "GET / HTTP/1.1\n" | ./var/hack/bin/nc -w 3 checkip.dyndns.org 8245 | grep Address | ./var/hack/bin/cut -d "<" -f7 | ./var/hack/bin/cut -c 25- > /var/log/external_ip
But the Kernel log entries remained the same...
Aug 17 09:37:54 (none) kernel: tcp_keepalive: call keepopen(0x803c3bc0)
Aug 17 09:38:58 (none) kernel: /var/hack/scripts/autodnsupdate: line 82: 1195 Terminated sleep 1800
Aug 17 09:38:59 (none) kernel: /var/hack/scripts/autodnsupdate: /var/hack/scripts/autodnsupdate: /var/hack/scripts/autodnsupdate: nc: command not found
Aug 17 09:38:59 (none) kernel: cut: command not found
Aug 17 09:38:59 (none) kernel: cut: command not found
Aug 17 09:38:59 (none) kernel: External IP has not changed from
Aug 17 09:38:59 (none) kernel: autodnsupdate has run 4 times since last update
Aug 17 09:39:09 (none) kernel: tcp_keepalive: call keepopen(0x80ea90e0)

I also added my PATH & LD_LIBRARY commands to the script more out of desperation than an expectation it was going to help as they were all in /.profile anyway.
PATH=/var/hack:/var/hack/bin:/var/hack/scripts
LD_LIBRARY_PATH=/var/hack/lib:/var/hack/bin
I also added a couple of lines from the version of cron I have running as the comments from the crontab file example suggested they might be helpful
# for TiVo: This file doesn't use a user field like system-wide crontabs
# normally do. Everything runs at uid 0 (not that it matters for TiVo).
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/var/hack/bin

# The following environment variables are needed for many tcl scripts to
# run. Thanks to AlphaWolf for troubleshooting this.
MFS_DEVICE=/dev/hda10
TIVO_ROOT=""
Sadly I still get exactly the same Kernel errors indicating that the script is running OK but can't find the nc and cut programs to actually function :(

As the command line version has worked OK I've commented the sleep command and uncommented the cron line in "autodnsupdate".
I've added a line to my crontab file to run the script every 30 minutes and see how that goes.

# m h dom mon dow command
0 06 * * 0-6 /var/hack/dailymail_jazz.tcl &
*/30 * * * * /var/hack/scripts/autodnsupdate &
#*/10 * * * * date >> /var/hack/cron.test.out

So I guess the next step is to look for why the script can't find nc and cut when started from rc.sysinit.author. It's probably something that an experienced Tivo hacker can spot but I'm not one of those!

AMc UK
08-17-2007, 10:30 AM
Update....
I rebooted to remove the rc.sysinit.author instance of autodnsupdate.

Cron has run autodnsupdate a few times now but my DynDNS account still has the same 99.99.99.99 IP I set to test :(

/var/hack/cron/log shows
cron (08/17-12:00:00-155) CMD (/var/hack/scripts/autodnsupdate )
/var/log/ipruns is also there with 2
/var/log/external_ip was created but is empty
/var/log/autodnsupdate.log isn't there at all.

If I run the same script from the command line then the IP updates, autodnsupdate.log is created with the right HTTP headers etc.

Very odd - something about running the script automagically upsets it :(

ciper - any ideas or ways to add more debug to the script?

ciper
08-17-2007, 07:05 PM
Good post. Plenty of detail so that I can try to wrap my head around what is happening. My first guess was that you were launching the script before your "export PATH=$PATH:/var/hack/bin" line in the rc.sysinit.author BUT that shouldnt have been a problem once you wrote the complete path into the script.

Its pretty confusing that the script works perfectly when run manually but fails when started automatically. Ill post a copy of my rc.sysinit.author in the case that you notice something different from yours. BTW I'm using free wifi and Im telneting to my tivos dynamic domain name to post this :)

#start
echo "start rc.sysinit.author"
sync

echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/var/hack/bin/lib"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/var/hack/bin/lib
echo "export done"

echo "export PATH=$PATH:/var/hack:/var/hack/bin"
export PATH=$PATH:/var/hack:/var/hack/bin
echo "path done"

echo "/sbin/tnlited XX /bin/bash -login &"
/sbin/tnlited XX /bin/bash -login &
echo "telnet done"

echo "sleep 15"
sleep 15

echo "/sbin/tivoftpd"
/sbin/tivoftpd -p XX &
echo "tivoftpd done"

echo "/var/hack/mfs-ftp/vserver &"
/var/hack/mfs-utils/vserver &
echo "vserver done"

echo "/var/hack/tivowebplus/tivoweb console &"
/var/hack/TivoWebPlus/tivoweb &
echo "tivoweb done"

echo "/var/hack/autodnsupdate"
/var/hack/autodnsupdate &
echo "autodnsupdate running"

echo "finished rc.sysinit.author"
All of those extra echos write entries to the kernel log. I censored the port numbers on my FTP and Telnet lines. The sleep line is so the tivo can finish booting before launching any extra stuff.

ciper
08-22-2007, 06:10 AM
Heh, an alternative method to creating your auth string has been found after reading RFC 2617. Come to find out its simply a base64 encoding scheme.
Use this website http://www.motobit.com/util/base64-decoder-encoder.asp and enter the string as "myusername:mypassword" and press "convert source data"

AMc UK
08-22-2007, 06:33 AM
Post #13 has my complete rc.sysinit.author file - my ftp etc. is launched from rc.sysinit courtesty of the network card install program that came with my cachecard. As I said it doesn't seem to prevent the script running, but the script isn't able to find cut nc etc. and even the nth run still fails with the same issues so its nothing much to do with start up.

Unfortunately my attempt to run it with cron resulted in the same "nc not found" errors so it has something to do with paths and users :(

I guess the next step for that is to export both my PATH and LD_LIBRARY_PATH from rc.sysinit.author to help it along.

I resorted to running it at the command line with the sleep command open, backgrounded with & and then closed the telnet session. This left the script running and waking as before. Reboots are fairly rare on this Tivo and it's on a 30 min UPS so it shouldn't be a problem for now.

A bit more pressing at the moment is the fact that the authorisation is failing so my IP isn't updating.
/var/log/autodnsupdate.log/
HTTP/1.1 403 Forbidden
Date: Tue, 21 Aug 2007 23:48:41 GMT
Server: Apache
X-UpdateCode: X
Content-Length: 7
Connection: close
Content-Type: text/html; charset=iso-8859-1

badauth

-------------
/var/log/ipruns/
20
-------------
/var/log/external_ip/
not the same as the one set in DynDNS

The HTTP authorisation string is the same as are the logon credentials at DynDNS so either DynDNS doesn't enjoy being updated that frequently or there is something more wrong in the HTTP authorisation.

I need to do some digging into the authorisation to make sure the string is always the same for the same user/password but I have no time to do that today :(

ciper - if you have any suggestions feel free to pitch in.

AMc UK
08-23-2007, 08:52 AM
Hmmm must have missed the second page....
I get a slightly different authorisation string with that base64 enocoder so maybe that will be OK.
Weirdly either would update from 1.2.3.4 to the valid current IP but previous string would fail with authorisation problems when it ran by itself after 24 hours.

Changing the string, manipulating ipruns to 48 and it authorises OK on the first run ... time will tell I guess.

BTW it might be an idea to ammend
if [ "$IPRUNS" = "48" ] ; then
to
if [ "$IPRUNS" > "47" ] ; then
So if it misses for some reason it will try again until it's successful I guess the downside would be it could call over and over locking the account anyway - not sure if it makes a difference. I just fiddled ipruns to 49 expecting it to trip and instead it pushed ipruns to 50 :)

AMc UK
08-29-2007, 09:10 AM
More "badauth" problems meant it failed to spot another IP change :(

Made some additions to rc.sysinit.author to export the path and rebooting now - still only time will tell as the first rerun always seems to succeed ?!?

AMc UK
08-31-2007, 05:44 AM
Hmmm partners VPN software crashed the WDS repeater Tivo was connected to so it couldn't run (daily call over network also failed).
That parameter definitely needs to be >47 or >=48 depending on what syntax TCL likes.
Obviously the failure negates the testing other than I know yesterday the authorisation was working but showing "no change" in the HTTP body (/var/log/autodnsupdate.log)

AMc UK
09-06-2007, 09:11 AM
Looks like adding those export lines to rc.sysinit.author and ammending the Base64 encoding has done it! :D

Had to reboot for another reason and this from the Kernel log shows it all going out as planned on boot.

Sep 6 11:45:43 (none) kernel: AMc export LD_LIBRARY_PATH=::/var/hack/lib:/var/hack/bin
Sep 6 11:45:43 (none) kernel: AMc export LD_LIBRARY_PATH done
Sep 6 11:45:43 (none) kernel: AMc export PATH=/bin:/sbin:/tvbin:/devbin:/bin:/sbin:/tvbin:/devbin:/var/hack:/var/hack/bin:/var/hack/scripts
Sep 6 11:45:43 (none) kernel: AMc export PATH done
Sep 6 11:45:43 (none) kernel: AMc tivoweb running
Sep 6 11:45:43 (none) kernel: AMc endpad.tcl -s 1 -e 6 -sugqual 75 -sugeq -auto
Sep 6 11:45:43 (none) kernel: AMc cron running
Sep 6 11:45:43 (none) kernel: AMc Autodnsupdate running
Sep 6 11:45:43 (none) kernel: rc.sysinit is complete
Sep 6 11:45:44 (none) kernel: turbonet2: driver version 20050218
Sep 6 11:45:44 (none) kernel: turbonet2: using MAC address 00:0B:AD:CC:4E:2D
Sep 6 11:45:44 (none) kernel: turbonet2: driver successfully installed
Sep 6 11:45:44 (none) kernel: turbonet2: driver successfully installed
Sep 6 11:45:44 (none) kernel: MCP startup complete
Sep 6 11:45:44 (none) kernel: IP struct was not filled in!
Sep 6 11:45:44 (none) kernel: sa is: 0x20000 0xc0a80b0c 0x7ffffcd4 0x7ffffcf0
Sep 6 11:45:44 (none) kernel: sa.sin_addr = 0x7ffffc38 a sockaddr is 16 bytes
Sep 6 11:45:47 (none) kernel: turbonet2: link = 100Mbps full-duplex
Sep 6 11:46:04 (none) kernel: External IP has not changed from 82.20.4.135
Sep 6 11:46:04 (none) kernel: autodnsupdate has run 6 times since last update


Last few days I've had these entries in autodnsupdate.log which suggest that unchanged and changed IPs are being dealt with.
/var/log/autodnsupdate.log/
HTTP/1.1 200 OK
Date: Tue, 04 Sep 2007 21:24:38 GMT
Server: Apache
X-UpdateCode: n
Content-Type: text/plain
Connection: close
Transfer-Encoding: chunked

14
nochg 81.XXX.XXX.XXX
0/var/log/autodnsupdate.log/
HTTP/1.1 200 OK
Date: Thu, 06 Sep 2007 00:26:49 GMT
Server: Apache
Content-Type: text/plain
Connection: close
Transfer-Encoding: chunked

10
good 82.XX.X.XXX
0

rc.sysinit.author looks like this for reference
#!/bin/bash

echo "AMc Running export LD_LIBRARY_PATH=$LD_LIBRARY_PATH::/var/hack/lib:/var/hack/bin"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH::/var/hack/lib:/var/hack/bin
echo "AMc export LD_LIBRARY_PATH done"

echo "AMc Running export PATH=$PATH:/bin:/sbin:/tvbin:/devbin:/var/hack:/var/hack/bin:/var/hack/scripts"
export PATH=$PATH:/bin:/sbin:/tvbin:/devbin:/var/hack:/var/hack/bin:/var/hack/scripts
echo "AMc export PATH done"

/var/hack/tivoweb-tcl/tivoweb
echo "AMc tivoweb running"

/var/hack/endpad.tcl -s 1 -e 6 -sugqual 75 -sugeq -auto >> /dev/null &
echo "AMc endpad.tcl -s 1 -e 6 -sugqual 75 -sugeq -auto"

/var/hack/bin/cron &
echo "AMc cron running"

/var/hack/scripts/autodnsupdate &
echo "AMc Autodnsupdate running"

A big thanks to Ciper - I've got my external Tivo access back which I lost when I went from cable to DSL!