Scripting class questions 1


1. using wget or curl, and a for loop, download all of the following images:

2. using a loop, backticks (`) and the basename command, rename all of the images, adding “(modified)” to their filenames

3. using a loop, backticks, basename, and the convert command (part of the imagemagick image processing suite), resize all of the images to 50% of their original size

4. using wget or curl,tar, a loop, oggdec and lame, convert the following files into mp3s:

5. (hard) repeat question 4, but retain all ID3 tag information.

6. Use a loop and the “uptime” and “free” commands to record the system load once a minute for the duration of the class. Store the information in CSV format. Use a spreadsheet to draw graphs of this information.

File management

1. Download the following tar.gz, and extract it using the tar command. In the resulting directory, find the newest file that matches name-asdf*.

System commands

1. Write a cron job that will email you the free space on your hard disk once per hour. Its output should be:

Hello, your hard disk has X% of hard drive space remaining!

2. Using the “du” command, find out which of the directories in the root directory of your hard drive is using the most hard disk space. Suggest some files you might delete if you were running out of space.

3. Use the find command to return a list of the files in your home directory that you have modified in the last week. Exclude anything that is not a regular file.

Regular expressions


Posted in questions, scripting | Leave a comment

Resizing a VirtualBox Hard Drive HOWTO

Update: There’s another method here that skips the use of clonezilla and does everything with gparted: Re-sizing a VirtualBox Virtual Disk Image File

VirtualBox doesn’t currently offer any tools for directly resizing a hard drive image (VDI). This method, using only free software tools, allows you to perform that task without any risk of losing the data you currently have on the image.

First, we’ll create a new, larger VDI, then we’ll use Clonezilla to clone our old one to the new one, then we’ll use Parted Magic to resize our partitions to fill our new, larger VDI, and finally will remove our old VDI from our machine image. This method assumes a linux client, but it should be equally applicable to a windows client (probably easier, given that there is no swap partition).

Download clonezilla live (stable release):
Right click on the machine, settings
Storage, click on the SATA Controller, Add Hard Disk
Create new (larger) VDI disk image
You should now see two VDI images listed under SATA controller
Click on the CD drive, underneath the IDE controller
Under attributes, click the CD icon, choose a virtual CD/DVD disk file…
choose the clonezilla live iso image you downloaded
Click OK
Boot the machine
Start Clonezilla live
– English
– Select keymap from full list
– pc / qwerty / British / Standard / Standard
– Start Clonezilla
– device-device
– Expert
– local disk to local disk clone
– sda as source
– sdb as target
– check the -r and -q1 options. -q1 is required because the faster methods fail in virtualbox for some reason. Slower, but works. 🙁
– Use partition table from source disk
– Enter to continue
– yes, we’re sure we want to continue
– yes, again, we’re sure
– yes, clone the bootloader
– yes, we’re sure!
– once it completes, 0 to power off
– Enter
Download Parted Magic:
Go into settings of the machine again. Change the sata ports around so that the new drive is on SATA Port 0 and the old one on SATA Port 1. We can remove the old one once we’re sure the new one works.
Click on the CD drive, underneath the IDE controller
Under attributes, click the CD icon, choose a virtual CD/DVD disk file…
choose the pmagic iso image
Start the machine
– Boot with default settings
– Button bottom left -> System Tools -> Parition editor
– Resize the extended partion to take up all remaining space (right click -> resize/move)
– Then do the Resize/move on /dev/sda5 (swap). Change the free space following to 0 (this moves it to the end). Click OK on the warning dialogue.
– Resize the extended partition down to maximise the free space preceding it. OK on the warning message.
– Resize /dev/sda1 to use up all the free space.
– Click the Apply button.
– Click Apply to continue.
– Click close when it’s done.
– Bottom left button -> logout -> shut down
Settings of the machine again
Remove the iso image from the CD drive, then click OK.
Start the machine. If it boots OK (did for me), we can shut it down and remove and delete the old VDI hard disk image.

Posted in HOWTOs | Tagged , , , , , , , , , , , , , , , , | 4 Comments

Bash Guide for Beginners, chapter 4 solutions

Solutions to:

grep bash /etc/passwd | cut -d: -f1


grep "^daemon" /etc/group


grep --invert-match "^daemon" /etc/group

4. info with line numbers:

grep -n localhost /etc/hosts

number of occurrences of string:

grep -o localhost /etc/hosts |wc -w


cd /usr/share/doc
for file in *
	if grep "$file" /etc/shells > /dev/null
		echo "$file"


for file in *
	if grep "$file" /etc/shells > /dev/null
		sum=`expr $sum + $(find "$file" -name README |wc -l)`
echo $sum


find . -mtime 0.42 -type f
for file in *
	if [ `stat -c %Y "$file"` -gt `expr $(date "+%s") - 36000` ] && [ -f "$file" ]
		echo "$file"



grep -c ".*" test


grep "^/dev" /etc/fstab | awk '{print $1}'
grep -o "^/dev[^[:space:]]*" /etc/fstab


if grep "^$user:" /etc/passwd > /dev/null
	echo user $user exists in the fstab
	echo user $user does not exist in the fstab


cd /etc
ls |grep [0-9]
ls |grep "[[:digit:]]"
Posted in answers, scripting | 2 Comments

Banana Bread Recipe

125g butter
1 cup sugar (I use half white half dark brown)
1 egg
3 ripe bananas
1.5 cups flour (half wholemeal, half white)
1 tsp baking soda (bicarb soda)
3 tbsps milk

beat butter and sugar until creamy
add eggs, beat, fold in flour with well mashed bananas (I blend the bananas first)
dissolve soda in the milk, add and mix well

bake at 360F (180C) for one hour, check close to the end to avoid burning

Posted in Recipes | Tagged , , | Leave a comment

How to change a headlight bulb on the Honda Varadero XL125V

I couldn’t find any info on this on the internet, and the French version of the user manual doesn’t have any info on this simple task either, so once I worked it out I figured I might as well post a howto here.

First, you need to remove the small plastic cover directly below the instrument panel (just below the speedo/tacho).  It is held in place by two plastic lugs on either side.  Unscrew these and remove the cover.  Things are annoyingly tight and fiddly in here.  You need to pull back the circular rubber cover over whichever side you need to get at.  It should have a tab that you can grab to pull it back.  Once you do that, you will be able to see the back of the headlight assembly.  Grab the black plastic part and rotate it, on mine it’s in an anti-clockwise direction (you might need to push the handlebars to the other side in order to have space to get your hand in).  It will rotate about 45 degrees and be released from its restraints.  You can then pull it out, remove the wires.  On mine, looking from the back, I have green, white, blue in a clockwise direction.  These are just slide-on, so you can just pull them off to better get at the assembly.

To remove the bulb you need to push it in, and rotate it, I think anti-clockwise.  Replace the bulb and reverse the above instructions to get everything back together.  Hope this saves someone some time.

Posted in HOWTOs | Tagged , , , , , , | 7 Comments

Monet’s Lilly Pond

IMG_4848, originally uploaded by Rob Hutton.

Our day at Monet’s garden was interesting. Up as early as we could from the beautiful Gîte, and an hours’ walk from Vernon over to Giverny. On our walk though, seven coaches full of tourists sailed past, so we knew what we were going to be in for.

Once we got to Giverny we just wandered around until we found the tourists. Lots of Americans (they talk loudly) and Germans (who tend to push). Once inside the gardens, however, a strange relaxation came over me, despite the crowds, and despite the men in boats in the lilly pond chopping up weed with a lawnmower-like contraption.

The garden is always changing; if you’re expecting to see exactly what Monet painted, you’ll be disappointed unless you’re there at the right time of year. But there’s a kind of magic in just seeing what inspired him, and imagining him there in the garden with his canvas, paint and brushes, looking out over his quiet, secluded garden, without the slightest idea that decades later it would be so thoroughly invaded by hordes of rubberneckers.

I was quickly drawn in to my photography, and Ris wandered off to spend her own time in the garden, so I was free to play. The challenge became to find a vista without thousands of people in it. Another was to not be too amused by all of the other photographers in the garden, hundreds of them, some snapping photos of every flower in their path as if the memory of Monet could imbue them with some miraculous artistic worth. However, the power of the garden is such that it still seems to be such a peaceful place, despite the heaving throng within it. Monet’s gift wasn’t just as a painter, but as a gardener and a lover of plants.

Posted in Europe | 1 Comment


For some time now, I’ve been working on bits of OpenStreetMap.  For those who don’t know, it’s like a fusion of Wikipedia and Google Maps, where all the of the map data is intended to be freely available (currently under a CC attribution sharealike license).  I’ve decided to compile a list of links to the major bits that I’ve worked on.

  1. Anglesea (mapped over a few days on motorbike/foot)
  2. North Melbourne (lots of back alleys)
  3. Thornbury
  4. Lake Pedder impoundment

More minor bits that I have worked or am working on:

  1. Mentone Grammar and its Playing Fields
  2. Cathedral Range State Park
  3. Great Otway National Park
Posted in Uncategorized | Leave a comment

TempMate HOWTO

I just got a query based on my earlier FridgeMate HOWTO.  Adam asks how to wire up one of these TempMates from CraftBrewer, so I worked up a wiring diagram based on that from the FridgeMate.  If you have any questions about wiring this up, refer the the FridgeMate howto first, as chances are you question will be answered there.

To be honest, I’m a bit surprised that they’re selling these things without an adequate wiring diagram, there’s definite potential for someone to kill themselves with this stuff.

Usual warnings apply, I’m not responsible if you kill yourself or burn your house down or anything, I’m just trying to help, and I’m not an electrician.

Posted in HOWTOs | 1 Comment

Extended battery pack for the Openmoko Neo Freerunner

Recently I bought myself an OpenMoko Neo FreeRunner phone.  It’s a lovely little smartphone that runs Linux, and it is special in that the manufacturer (FIC) has gone to extreme lengths to ensure that all the hardware is open (that is, it has either an open source driver or open documentation (prefeably under a CC license to prevent them disappearing).

Anyway, the application that has got me most excited about the phone (apart from the terminal ;)) is TangoGPS.  In combination with OpenStreetMap (wiki meets maps), it’s great fun (in a creative/geeky kind of way I suppose… I’m wondering why it’s got me so interested, but that might have to be the subject of another post).  The trouble is that the phone has to be on the whole time so that it can recieve GPS signals.  TangoGPS appears to use a lot of CPU as well, so it tends to eat the battery, giving a battery life as bad as four hours.

I bought an iRiver music player a few years ago.  It came with a AA battery pack which I never used because the player had a 12 hour battery life anyway.  But it got me thinking.  Wouldn’t it be really easy to adapt it for the OpenMoko Freerunner?  Turns out it was.

Continue reading

Posted in OpenMoko | 3 Comments

Another one of Gemma’s questionaires

Pinched off Gemma!

The Basics
Hair Color: brown
Eye Color: brown
Height: 178cm, 5’11”
Profession: Information Technology Officer
Relationship Status: steady partner
Religious Views: atheist

My Favorites
Favourite Colour: red
Favourite Movie: Blade Runner, the Director’s Cut
Favourite Hobby: Brewing beer
Favourite School Subject: There are two: Software Development, Principles and Tools and first year Biology.
Favourite Vacation Destination: Snow/Beach
Favourite Food: Indian

This or That
Chocolate or Vanilla: Chocolate
Big Mac or Whopper: Whopper
Coke or Pepsi : Coke
Beer or Wine: Beer
Coffee or Tea: Coffee
Apple Juice or O.J.: O.J., tho juice has too much sugar in it for me to drink it much.
Facebook or MySpace: Facebook
Summer or Winter: Winter
Windows or Mac: Linux
Cats or Dogs: Dogs
Boxers or Briefs: Boxers
Movie or Play: Movie

Do You?
Have Any Pets: No
Have Any Children: No
Smoke: No
Drink: Yes
Exercise: Irregularly
Spend Your Life On Facebook: No
Play On A Sports Team: No
Belong To Any Organizations: EMS
Love Your Job: Nah, but it’s OK
Play An Instrument: Yep
Sing: In tune but crappy otherwise.

Have You Ever

Stolen Anything: Not really.
Been Drunk Before Noon: Probably, but not that I remember.
Had Sex In A Public Place: Yes
Got Caught Telling A Lie: Probably.
Got A Speeding Ticket: Nup
Been Arrested: No
Cheated In A Relationship: No
Cried During A Movie: All the time.
Had A One Night Stand: Yes

Posted in Uncategorized | 3 Comments