In my previous post I talk about needing a TFTP server in order to serve some files to a hardware device. This post describes how I used expect to automate the process of logging into the hardware device and issue commands that copy in a config file, commit it to the device, upgrade the firmware and finally tell the device to reset to factory defaults and reboot.

Expect is a way to programmatically work with a normally interactive process. Using expect you can write a script that telnets into a system and then issues commands based on what it “sees.” Here is the script I used, with some important values removed, to automate the process of updating a number of devices.

#!/usr/bin/expect
set timeout 300
spawn telnet 192.168.1.1
expect "login: "
send "root\n"
expect "Password: "
send "tehmagicphrase\n"
expect "# "
send "cd /tmp \n"
expect "# "
send "tftp -g -r config.ini 192.168.1.159\n"
expect "# "
send "config.sh import config.ini\n"
expect "# "
send "tftp -g -r firmware.img 192.168.1.159\n"
expect "# "
send "firmware_upgrade /tmp/firmware.img 1\n"
expect EOF

The above script was saved into a file called pushConfig.expect and set as executable using ‘chmod +x pushConfig.expect’. To run the script, I powered on the device and waited for it to be ready, once ready I issued ./pushConfig.expect to start the update process.

Using expect is fairly straightforward. The most difficult part is ensuring you correctly tell expect what to look for before sending the next command. In the script above I do the following:

set timeout 300

This tells expect to wait at least 5 minutes for matching text before continuing to the next send command. What this means, is if I tell it to send some data it’ll wait up to 5 minutes to see what is in the expect line after the send. In the case of my script the firmware upgrade could take quite a bit of time and I didn’t want it to timeout so I set the value fairly high.

The next line tells expect to start a telnet session to a remote machine and then to wait until it sees:

login: 

Once it sees that it sends the username. The script continues like this until it sees EOF. At this point expect knows that the process is now complete and it exits.

By using an expect script I was able to simply power on the hardware device and wait for it to boot. Once booted I ran the script. This saved me and a co-worker a lot of time while pushing custom configurations and upgrading the firmware on a number of devices.

Expect is capable of a lot more than I used in my example and can react differently based on what it receives back from the interactive process or even loop over a series of commands. To learn more about expect try ‘man expect’ or search your favorite search engine.

Ran into a situation today where I needed a tftp server in order to serve files to a hardware device. Normally I would have fired up a Linux system to get the job done but it hit me (again) that I’m using a UNIX operating system and it’s bound to have a tftp server built in. Sure enough I found it hiding on the system but I couldn’t get it to run. After some searching around I found my answer and I thought I’d post it so hopefully someone else will find it.

If you want to run the tftp server issue the following command:

sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist

This will cause the tftp server to load and stay running until it either crashes or you restart your system. If you want to ensure that tftp is always running issue the following:

sudo launchctl load -w /System/Library/LaunchDaemons/tftp.plist

To stop the tftp server issue the following command:

sudo launchctl unload /System/Library/LaunchDaemons/tftp.plist

To permanently disable tftp issue the following command:

sudo launchctl unload -w /System/Library/LaunchDaemons/tftp.plist

Came across this article talking about progress being made with the new Apple TV in regards to jailbreaking and adding new functionality. Jailbreaking was recently ruled as legal. I think this is a big win for consumers who want to be able to use their hardware devices for whatever they want. For example, I think it’s ridiculous that Apple is allowed to force me to join their developer program if I want to write my own iOS application for a device I own. It’s perfectly reasonable that if I want to distribute my software using their App Store platform but beyond that I should be faced with such restrictions.

Also, just because jailbreaking has been deemed legal doesn’t mean pirating software is suddenly legal as well. There are still plenty of other existing laws protecting against that. In the next few months or years I think we’ll see additional clarifications with the DMCA and jailbreaking. For example, although the iPhone was specifically mentioned in the ruling, I actually don’t think it should be ok to jailbreak an iPhone for security reasons as it pertains to the cell phone network. The iPhone is part of a bigger infrastructure that is not owned and operated by the owner of the phone and in that case it’s a lot like a business PC being connected to a business network. At the same however, such a ruling will hopefully coerce Apple into providing a toggle on the phone allowing end users to install software outside of the App Store. This would satisfy what some end users want while still protecting the security of the cellular network.

Xmarks has decided to close up shop because it can’t find a way to make any money. Sad to me because it’s a service I use everyday and is honestly something I’d probably pay for because it works across all browsers on all the systems I care about. Although it is possible to use your own server as an xmarks sync server this is really only a stop gap measure because the plugin is going to need to be continuously updated as new browsers are released. The only answer then is for someone (are you listening Google?) to buy it out or for the team to release it as an open source project.

Ran into an issue while trying to get 64 bit Coldfusion running on Snow Leopard. Somehow Adobe’s installer can’t deal with the fact that the java binaries are symlinked in OS X so you have to manually remove the symlinks and then copy the binaries over. This page documents how to do it. The only thing I did differently is instead of simply deleting the symlinks I created a directory and moved them into that. This way I can restore the system back to normal.

Microsoft celebrated the RTM of Windows Phone with an incredibly awkward mock funeral for iPhone and BlackBerry. Apparently Microsoft is either not worried about Android or they don’t think Windows Phone 7 can compete with it. Either way, claiming to have buried the competition before the general public actually has Windows Phone 7 devices is a bit premature and I really hope it doesn’t mean Microsoft thinks it can now just sit back and relax.

http://www.neowin.net/news/microsoft-workers-celebrated-windows-phone-7-rtm-with-iphone-hearses

AppleInsider is running a story about a possible iPhone 4 launch on the Verizon network in 2011. This seems to jive with a bit of information from I got from a Verizon worker on the roll out of LTE beginning sometime in the end of 2011 or beginning of 2012. In fact, towers in the Fargo ND area are being upgraded to LTE capable equipment right now. I have my doubts we’ll see a CDMA only version of the iPhone on Verizon’s network and I am betting on a simultaneous iPhone and LTE launch. iPhone being the first LTE capable phone on Verizon’s network would be big marketing win for both the iPhone and Verizon.