chriscoughlin.com
In The News

July 21, 2007

Screenshot of SkinDepth2

Want to be a Windows and/or Linux beta tester for the next version of SkinDepth2? Let me know.

July 20, 2007

As promised, a quick and dirty script to automate backups with rsync and the chkmnt.sh script I posted on the 13th. I'll post a link for download shortly, but if you're just too excited and need to get started now, here you go:

	#!/bin/sh
	# Usage:  backup.sh original_folder backup_drive destination_folder
	# Where original_folder is the file to back up e.g. /home/ccoughlin,
	# backup_drive is the drive to back up to e.g. /mnt/sda1 (no trailing slash!), and
	# destination_folder is the folder on the backup drive to back up to e.g. /mnt/sda1/backups
	# 
	# Example usage: ./backup.sh /home/ccoughlin/bin /media/sda1 /media/sda1/backup
	# Checks that the drive /media/sda1 is mounted, and if so backs up the folder /home/ccoughlin/bin to the folder /media/sda1/backup

	/home/ccoughlin/bin/chkmnt.sh $2 > /dev/null

	if [ $? -eq 0 ] ; then
		# If you were backing up to a Linux partition
		# rsync -avz -e "ssh -i /home/ccoughlin/backupkey" $1 $2
		# FAT32 partitions don't support many rsync options, so we need to use a different approach
		# We run as sudo because FAT32 volumes mounted with UID root will complain about trying to set file times
		# Alternatively could mount as the UID of the user
		sudo rsync -rvt --modify-window=1 -e "ssh -i /home/ccoughlin/backupkey" $1 $3
	else
		echo "Drive ${2} is not mounted, aborting."
	fi
	

The script assumes that you'll be using the most excellent Engadget Backup Tutorial as a starting point. If not, you can safely substitute your backup commands. Chances are you probably don't need ssh to back up to your FAT32 device, but I opted to keep everything the same between FAT and extX filesystems-no sense changing if you don't have to.

To automate the works, you can add this script to your list of cron jobs or any other method you prefer. Personally I like using the at command because it's a little more human-readable I think. For example, if you want to run the backup once a day, create a script backmeup.sh with something like the following contents (assuming your actual backup script is backup.sh):

	#!/bin/sh
	/home/ccoughlin/bin/backup.sh
	at -f /home/ccoughlin/bin/backup.sh now + 1 day
	

Just run this script once, and from then on once a day your backup will be done. Use the commands atq to make sure it's scheduled, and atrm to delete it as a recurring job.

July 13, 2007

A posting from the "useful shell scripts" department today...if you've got an external hard drive and you'd like to use unison or rsync to automate backups, you'd probably like to automate the whole procedure. The problem is that if you tend to move your external hard drive around like I do, you can't always guarantee that the drive's available.

I wrote a simple little shell script that parses the output of df to find out if a given drive is mounted:

	#!/bin/sh
	found_drive=$(df -h | grep ${1} )
	if [ -n "$found_drive" ] ; then
		echo "Drive $1 mounted!"
		avail_space=$(echo "$found_drive" | xargs | cut -d" " -f4 )
		used_space=$(echo "$found_drive" | xargs | cut -d" " -f3 )
		total_space=$(echo "$found_drive" | xargs | cut -d" " -f2 )
		echo "Size of drive:  $total_space"
		echo "Used space:  $used_space"
		echo "Available space:  $avail_space"
		exit 0
	else
		echo "Drive $1 not mounted!"
		exit 1
	fi
	

To use it, simply supply it with a device to check, e.g. chkmnt.sh /dev/sda1. Run by itself on the command line, this will report if the device is mounted and if so report on its usage. To use it interactively just check its return value-it returns 0 if the drive's available, 1 if it isn't. Example:

	#!/bin/sh
	/home/ccoughlin/bin/chkmnt.sh $1 > /dev/null

	if [ $? -eq 0 ] ; then
		echo "Drive ${1} is mounted, proceeding with backup."
		# Backup commands follow
	else
		echo "Drive ${1} is not mounted, aborting."
	fi
	

I'm putting the final polish on a rsync script to backup that uses this mount check, which I'll post in the near future. You can get fancier with this script-one suggestion would be to check to make sure that you have enough available space to make your backup, but this is a good starting point for now.

May 8, 2007

An update to the SkinDepth materials database today-several new materials have been added, including hard to find conductivities for graphite epoxy composites and for graphite itself. If you're using an older copy of SkinDepth you may want to swap databases, as the older values for GrEp composites apparently represented a composite with much higher electrical conductivity than is usually the case.

I'm thinking of redoing SkinDepth to be optimized for running from a thumbdrive and for generally increasing its abilities, is anyone interested? I'd love to get feedback on this.

I've also added a new ZIP archive to download, udp_finder, part of the how-to on automatically finding Coughlinux devices on a network. It's a simple C program, based in part on some of the concepts and code in this Wikipedia entry on UDP. In client mode, it broadcasts its IP and a command line specified serial number file to every IP in a network on a given port, e.g.

./udp_finder -p9090 -b192.168.1 -sMyID

Will attempt to contact every IP address from 192.168.1.0 to 192.168.1.255. In server mode, it listens on the given port and reports all clients reporting in, e.g.

./udp_finder -p9090 -l

Will print the IP and ID of every client that "calls in." I didn't use the UDP multicast feature in this sample, because it normally requires extended (read: root) privileges, and the Linux documentation for the system calls is a little ambiguous as to whether this feature is even implemented. So instead it simply calls each IP one by one; since UDP packets aren't guaranteed delivery like TCP, we err on the side of caution and send the same packet several times.

The project is a simple Eclipse CDT project, but it shouldn't be terribly difficult to use another IDE/editor to compile. In our LAHMP project, I configured it to report its location every 15 minutes and on initial bootup; so far it's worked as advertised in the field and across several different flavours of Linux. I wrote a simple Windows client to keep a running tally of LAHMP units that report in; if you're interested I could probably be persuaded to give you a copy.

Last Year's News