Thursday, September 09, 2010

DHCP renewals interrupt shell script

I was running a script to convert a bunch of Canon 5D photos from high res to HD resolution and noticed the script would die after 15-30 minutes.

It didn't seem likely that "convert" would die, as the script logged into the server that I was using to execute convert and I only executed convert once on that server:
for FILE in $(cat $FILES)
do
COUNT=$(expr $COUNT + 1)
NEWFILE=$(echo $FILE | sed 's/Remote\(.*\)/new\/\1/g')
echo "FILE $COUNT of $NUMFILES is $FILE, NEWFILE is $NEWFILE"
echo "converting $FILE to $NEWFILE"
ssh $CRED "/opt/local/bin/convert -verbose -resize 1920x1280 $FILE $NEWFILE"
echo
#break
done


Snooping in /var/log/syslog, I found that the DHCP server was renewing my IP address every 28 minutes or so:
Sep 8 07:47:52 ubuntu NetworkManager: address 192.168.0.95
Sep 8 05:02:22 ubuntu NetworkManager: address 192.168.0.95
Sep 8 05:26:27 ubuntu NetworkManager: DHCP: device eth0 state changed bound -> expire
Sep 8 05:26:27 ubuntu NetworkManager: DHCP: device eth0 state changed expire -> preinit
Sep 8 05:26:28 ubuntu NetworkManager: address 192.168.0.96
Sep 8 05:53:04 ubuntu NetworkManager: DHCP: device eth0 state changed bound -> expire
Sep 8 05:53:04 ubuntu NetworkManager: DHCP: device eth0 state changed expire -> preinit
Sep 8 05:53:08 ubuntu NetworkManager: address 192.168.0.97
Sep 8 06:21:25 ubuntu NetworkManager: DHCP: device eth0 state changed bound -> expire
Sep 8 06:21:25 ubuntu NetworkManager: DHCP: device eth0 state changed expire -> preinit
Sep 8 06:21:26 ubuntu NetworkManager: address 192.168.0.98
Sep 8 06:50:47 ubuntu NetworkManager: DHCP: device eth0 state changed bound -> expire
Sep 8 06:50:47 ubuntu NetworkManager: DHCP: device eth0 state changed expire -> preinit



What the hell? So I manually set the IP address of the box using these instructions from Jonathan Moeller:

The comment from Anurag fit my bill the best; ie, giving the complete network info to the /etc/network/interfaces files, including network and broadcast IPs.
ubuntu:~$ cat /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.0.98
netmask 255.255.255.0
gateway 192.168.0.1
network 192.168.0.0
broadcast 192.168.0.255


cheers,
sodo

Update 2010/09/13
Here's an example of a simple interfaces file with dynamic setting:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp

No comments:

Feel free to drop me a line or ask me a question.