Archives for June, 2010

9
Jun

Compare Two Directories or Filesystems Recursively

It’s so simple it doesn’t really need an entry, but there will be a time when somebody asks “how can I compare two different directories or file systems”, and I will say, “this way…”

diff -rq /dir1 /dir2

The -q option above will only tell you which files differ. It will not go into details and display each differing line of each file.

7
Jun

Script to Wait for Wireless AP Association During System Startup

The following is a script that could prove to be useful in an embedded Linux environment utilizing a wireless adapter. In order to connect to a wireless network, the wireless adapter needs to associate with an AP which can take some time occasionally. If you’ve edited the /etc/network/interfaces file to automatically obtain an IP address via DHCP, and it doesn’t seem to be getting an IP address during system startup, then this script might be able to help. This script is intended to run on system startup and wait for the access point association. If one is not found, it will eventually timeout.

#!/bin/bash
#
# CONNECT TO WIRELESS NETWORK
# Author: Errol E. Burrow II <eburrow@gmail.com>
#
# call this script from /etc/rc.local
# this script uses fping which can be installed
# with sudo apt-get install fping
#  

# globals
MYIP="192.168.0.121"
WAPNAME="SSVR3"
GATEWAY="192.168.0.141"
PINGTESTIP="10.10.10.1"
RETRYCOUNT=10

# turn on extra regex features
shopt -s extglob

until [ $RETRYCOUNT -lt 1 ]; do
	ifconfig wlan0 $MYIP
	iwconfig wlan0 essid $WAPNAME
	# get the access point mac address for wlan0
	ap=$(iwconfig wlan0 | sed "s/Access/~+&/" | tr "~" "n" | grep "+" | cut -c16- | tr -d " ")
	echo "access point mac: [$ap]"
	# check if the ap actually has an expected value
	if [[ $ap =~ [0-9a-f]{2}[:-] ]]; then
		echo "success: connected to wifi access point!"
		route add default gw $GATEWAY
		echo "added default gateway $GATEWAY"

		echo "testing ping to $PINGTESTIP"
		if fping -a -r1 $PINGTESTIP > /dev/null
			then
				echo "success: $PINGTESTIP is alive!"
				break
			else
				echo "warning: $PINGTESTIP cannot be reached!"
		fi
	else
		echo "warning: not connected to wifi access point"
		# try again
	fi
	echo "retrying connection: $RETRYCOUNT"
	let RETRYCOUNT-=1
	# sleep a bit
	sleep 1
done
4
Jun

Example Usage of cURL Utility

Here’s a core utility that will surely be of use for Linux or Mac users: cURL. In my own description, it’s sorta like wget, but different. Description from the website:

curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction.

Also, it might be good to note this as well now that I brought up wget:

Curl is not a wget clone. That is a common misconception. Never, during
curl’s development, have we intended curl to replace wget or compete on its
market. Curl is targeted at single-shot file transfers.

I took some time to play around with it a bit and found that it’s quite easy to use and the documentation and man pages are nicely laid out. For example, here’s how I used curl to download an image from a password protected website:

curl http://www.thewebsite.com/image.jpg --user theusername:thepassword > image.jpg

I wanted to see if I could download multiple files at a time, so I became a little fancier and threw in a for loop with the seq command for counting. Since I knew all of my images were taken in order (100.jpg -> 110.jpg), I could use something like:

for i in $(seq 100 110); do curl http://www.thewebsite.com/$i.jpg --user theusername:thepassword > $i.jpg; done

I’m sure that this hasn’t even scratched the surface for what curl can do, so be sure to check out the man pages and have fun with it!

3
Jun

Test Drive Gnome 3 Shell Compositing Manager Interface

The first thing you’ll need to do is ensure that window compositing is enabled through the “Preferences -> Desktop Effects”. Then, use the following commands in the terminal to install and try out the new Gnome Shell compositing manager (these were tested in Fedora 13, if you’re using Ubuntu, you will need to change “yum” to “apt-get”).

yum install -y gnome-shell
gnome-shell --replace
2
Jun

Easily Edit Binary Files with hexedit

Let’s pretend that you’ve made a mistake when creating a binary image and you didn’t realize it until after you painstakingly created this image for use in a production process. Well, instead of going back and doing it all over again, you can simply use hexedit to edit the binary file directly, saving you precious time.

hexedit -m binaryfile.dd

In my particular case, I was trying to create an SD card image for use in an SBC product and I didn’t realize until it was too late that there was a type-o in a script. I used hexedit to fix the type-o and everything worked out heavenly.

« Previous Page