Skip to content

Instantly share code, notes, and snippets.

@x2q
Created September 19, 2012 08:12
Show Gist options
  • Save x2q/3748339 to your computer and use it in GitHub Desktop.
Save x2q/3748339 to your computer and use it in GitHub Desktop.
Simple script to ping and then atftp a firmware image e.g. openwrt or dd-wrt
#!/bin/bash
# Simple script to ping and then atftp a firmware image
# Works on my machine and an ASUS WL-500g series router
# Usage: ./ping_atftp 192.168.1.1 openwrt-brcm47xx-squashfs.trx
EXPECTED_ARGS=2
if [ $# -ne $EXPECTED_ARGS ]; then
echo "Usage: `basename $0` ip-addr firmware-image"
exit 1;
fi
count=50
while [[ $count -ne 0 ]] ; do
ping -w 1 -l 3 -i 0.2 -t 0.01 -c 1 $1
rc=$?
if [[ $rc -eq 0 ]] ; then
count=1
fi
((count=count-1))
done
if [[ $rc -eq 0 ]] ; then
echo "The router is online."
atftp -p -l $2 --trace --verbose $1
else
echo "Timeout."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment