Monthly Archive for December, 2008

Zenity and rsync

Zenity is a neat little tool to create simple GUI’s for your shellscripts. One of its most useful features is the progress dialog, which allows one to show the progress of a command using the all-familiar GTK progress bar.

Zenity and rsync

Zenity uses pipes to send commands to the dialogs. Any number sent to the Zenity instance while in progress mode will make the progress bar move to that number as the percentage completed. Any text that starts with # is set as the label above the progress bar.

Here’s an example shamelessly stolen and abbreviated from the manual:

        #!/bin/sh
        (
        echo "10" ; sleep 1
        echo "# Updating mail logs" ; sleep 1
        echo "20" ; sleep 1
        echo "# Resetting cron jobs" ; sleep 1
        echo "75" ; sleep 1
        echo "# Rebooting system" ; sleep 1
        echo "100" ; sleep 1
        ) |
        zenity --progress \
          --title="Update System Logs" \
          --text="Scanning mail logs..." \
          --percentage=0

To shape the output of a real application into data fit for Zenity mostly requires some creative awking. I couldn’t find an example to parse rsync output, so I made this awk-script to show the progress of an rsync operation:

{
   if (index($0, "to-check=") > 0)
   {
	split($0, pieces, "to-check=");
	term = substr(pieces[2], 0, length(pieces[2])-1);
	split(term, division, "/");
	print (1-(division[1]/division[2]))*100"%"
   }
   else
   {
	print "#"$0;
   }
   fflush();
}

Use it like this.

$ rsync -av --progress /media/disk/ ~/backup/usbstick/ |
   awk -f rsync.awk |
   zenity --progress --title "Backing up USB-Stick" \
      --text="Scanning..." --percentage=0

rsync.awk contains the awk-script above. Mind how we use the parameter progress to tell how far we’ve progressed. This results in the dialog shown above.

Autographed

Last Thursday I went on my annual visit to the Bookfestival in Expo, Ghent. While my dad was disappointed by the lack of good comic books this year, I was delighted being able to pick up Stephenson’s Confusion, Morrow’s The Last Witchfinder, Simmons’ Olympos and a boxed edition of Clarke’s Jonathan Strange & Mr. Norrell for less than €19. A steal!
Jonathan Strange & Mr. Norrell

I got even more excited when back home I turned the first page of Volume 1 of Jonathan Strange & Mr. Norrell: The signature of Susanna Clarke!
Susanna Clarke\'s Signature
I have no idea if it’s real or pressed on. There’s no impression of the pen, but it is in blue ink. Nonetheless, a pleasant surprise.

Bargain Hunting in the UK

The pound sterling has taken a deep dive the last few months and continues to fall. Today it reached an amazing £1 = €1.07. For us euro-handlers this means we can pick up bargains on the other side of the pond. Since the UK is part of the European economic union, no import taxes need to be paid either.

Here’s a list of my favorite UK online stores:

The cheapest books can be found on The Book Depository, including worldwide free delivery. I’ve consistently had great experiences with them. Books ordered monday get delivered by friday.

Great gifts and gadgets can be had at Firebox.com. Shipping is a tad expensive though, at £13 to Belgium.

Play.com has always been my first stop to buy movies, music and games with good prices and free worldwide delivery. Unfortunately they use their own currency exchange rate which is still stuck at last decade’s £1 = €1.5. A great alternative is Amazon.co.uk, with excellent prices and cheap shipping. A CD or DVD is sent to Belgium for about £2, software for £5.

If anyone else knows of good UK shops, please post it in the comments. The more shops the better. Happy over-the-channel shopping!

Samsung Loses, Ultimate Boot CD Wins

To cut a long story short: I had 2 disks to test, one a Seagate and the other a Samsung.

Using Seagate’s diagnostics utility SeaTools was a very smooth experience. After booting from the CD, a GUI application automatically started, including mouse support. Even basic users would feel right at home.

Trying to get Samsung’s HUtil to work was a nightmare. Apparantly Samsung are as of yet unaware of the existence of SATA CD/DVD-drives. Using the CD my PC booted into FreeDOS just fine, but their script couldn’t detect the CD-drive so it couldn’t start the diagnostics utility. Trying it manually failed too because the included drivers simply don’t support SATA drives.

I spent half an hour going back and forth changing settings in the BIOS and rebooting to no avail. This worked for some people though, so ymmv. Check out any settings on SATA compatibility modes.

One post on the internet revealed a method of booting using the Ultimate Boot CD, then switching to Samsung’s CD, and running the diagnostics from there. After reading up on UBCD, turns out those last two steps aren’t even necessary. UBCD includes the latest diagnostics utility for any hard-drive out there! Just boot it, select the utility from the menu, and it automatically starts.

So if you ever need to do a diagnostics on a disk, don’t bother downloading and trying to boot the manufacturer’s utility. Just pop in the UBCD and you’re off. It also includes other stuff to do just about anything with your computer. Neat!

How-To: Wrap a romantic present using Schamper

So you need to wrap a romantic present, but you’re all out of wrapping paper. Or you never had any. As a student, I face this situation constantly, and have become quite adapt at surviving it.

The Victims
Here are the victims. I’m going to scavenge an old issue of Schamper, our university’s awesome student magazine, for wrapping paper.

My Favorite Article
Rip out your favorite or most romantic articles to use as wrapping material.

Two articles fused together
Use tape to paste every page together to make a long enough string of mind-blowing literature.

Wrap around
Wrap the string around the present. Use tape to paste the two ends together.

Cornered
There’s supposed to be a certain technique to do the corners neatly, but let’s face it: you’re wrapping her present using an old magazine. She’s not going to care about the corners. Also, I forgot.

Use tape vigoriously to make sure the enlightening wrapping doesn’t fall apart.

Missing side
If you missed a side, a common error, just paste a page on top.

FixedThat’s the beauty of this method: you can screw up and she’s never going to notice.

Nice Wrappings
Nothing says I love you like a big bald face on top of her present.

A job well done, another potentially problematic situation solved. You can tell her you custom-made the wrapping paper yourself, because that’s how much you love her!

Make Athena Go Local

If you’re a student at UGent and living in a dorm, you need to access the Internet through a VPN, but Minerva and Athena, a Citrix system, can be accessed locally. Using a clever line of commands, one can route all Athena traffic over the local network even though you’re connected through a VPN.

Obviously this will result in less lag when using Athena, but more importantly, it’ll also save precious megabytes of bandwidth from your VPN limit. All this while your regular internet connection remains untouched.

Type this in your shell:

for ip in `dig @ugdns1.ugent.be ugent.be axfr | grep citrix\
 | awk '{print $5}'`; do echo $ip;
sudo route add -net $ip netmask 255.255.255.255 eth0;
done;

It’ll find all Citrix-related addresses at UGent, and route them through your local network interface.

On the other hand, you need to connect through a VPN if you want to access Athena from outside of UGent. In this case, we can use our script to limit the VPN for Athena traffic only, and make all other Internet connections go locally. This will again save you precious megabytes from your VPN limit, while ensuring all other Internet traffic doesn’t get laggy.

sudo route add -net default eth0
for ip in `dig @ugdns1.ugent.be ugent.be axfr | grep citrix\
 | awk '{print $5}'`; do echo $ip;
sudo route add -net $ip netmask 255.255.255.255 tun0;
done;

Shell-fu

alias webshare='python -c "import SimpleHTTPServer;\
SimpleHTTPServer.test()"'

Want to show something on your machine to someone over the web? Don’t copy it or upload it somewhere. Just run “webshare” and the current directory and everything beneath it will be served from a new web server listening on port 8000. When your pal is finished, hit control-c.

Awesome.

Gems like this can be found on the aptly named Shell-Fu.