Today I had to find out which disks on Linux match up with the virtual disks on VMWare in order to remove some of them. This being quite a sensitive task, I spent some time figuring out how to do it consistently. Documenting it here for the afterworld:

$ lsscsi | grep VMware | while read scsi ig1 ig2 ig3 ig4 ig5 dev; do echo $dev - SCSI \($(echo ${scsi:1}|cut -d\: -f1)\:$(echo $scsi|cut -d\: -f3)\); done

Combining that with pvs to find emtpy physical volumes in Linux LVM gives you a sweet list of devices you can safely disconnect (after vgreduce and pvremove of course …)

$ pvs | sed 1d | while read dev vg ig1 ig2 size free; do if [ "_$size" == "_$free" ]; then echo -e "$dev \t SCSI ($(lsscsi | grep $dev | cut -d":" -f1,3 | tr -d "["))"; fi; done

One major drawback of isc-dhcp-client in Debian (in this case, Debian 6) is that the option to automatically update the hostname (like dhcpcd) is missing. I came a cross a post on debian-administration.org that discusses the problem together with a quite well documented approach on how to fix it. One problem is that, with a decently configured DNS server, the ‘host’ command returns the hostname with a dot at the end.

I updated the script to that it just takes the actual hostname to set it, and by sending a correct domain-name option you will end up with a decent setup (‘hostname’ is the actual, short hostname, ‘hostname –fqdn’ returns the hostname with the domain). Here’s how:

{% highlight bash %}
#!/bin/sh

Filename: /etc/dhcp3/dhclient-exit-hooks.d/hostname

Purpose: Used by dhclient-script to set the hostname of the system

to match the DNS information for the host as provided by

DHCP.

Depends: dhcp3-client (should be in the base install)

hostname (for hostname, again, should be in the base)

bind9-host (for host)

coreutils (for cut and echo)

#
if [ “$reason” != BOUND ] && [ “$reason” != RENEW ] \
&& [ “$reason” != REBIND ] && [ “$reason” != REBOOT ]
then
return
fi

echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
hostname=$(host $new_ip_address | cut -d ‘ ‘ -f 5 | cut -d ‘.’ -f 1)

echo $hostname > /etc/hostname
hostname $hostname

echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname

And that should just about do it…

{% endhighlight %}

Thank you!

Before I google that another time (I am pretty sure we’re standing a chance that google will explode in that case), here’s how you calculate sums using awk:

{% highlight bash %}
cat something | awk ‘{ SUM += $5} END { print SUM }’
{% endhighlight %}

Thank you!

Well, this is more or less personal. Still interesting. Needed to batch-swap audio track of some video files (stuff I ripped from DVDs to play in iTunes, and stupidly I selected the german audio channel to play first). When I couldn’t find a tool doing that, I decided to just explore how it’s done with ffmpeg. And here’s the outcome:

{% highlight bash %}
#!/bin/bash

filelist=$@
OLDVAL=1

list the available tracks

ffmpeg -i $1 2>&1 | grep Stream

printf “%s [%s]: ” “Enter audio track to use: ” “$OLDVAL”
read NEWVAL

for file in $filelist; do
ffmpeg -i $file -map 0:0 -map 0:${NEWVAL} -vcodec copy swap_$file
done
{% endhighlight %}

I often download files, may it be from the web or from my e-mail program of choice (at work: sadly Outlook, at home Mail) and need to do stuff with it in the console.

To speed up this process, I’ve written this small AppleScript. The ideas far outpace my abilities with AppleScript, so for now it only works in Finder (although it has stuff in it to prepare it to work universally, it currently doesn’t). I thought I’d share it anyway, so here it comes:

{% highlight applescript %}
— get active window
tell application “System Events”
— get the name of the frontmost application
set theApp to (name of the first process whose frontmost is true) as text
end tell

— debug
–tell application “Finder” to display dialog theApp

tell application theApp
— check if we have documents or, basically, Finder
set documentCount to count documents
— if we have documents, select the currently open one
if documentCount > 0 then
— fetch the document name
set theDocument to document 1
set theFile to path of theDocument
— chop the file name to cd to the directory
set tid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “/”
set chunks to text items of theFile
if last item of chunks is “” then set chunks to reverse of (rest of (reverse of chunks))
set theFilePath to quoted form of (reverse of (rest of (reverse of chunks)) as text)
set AppleScript’s text item delimiters to tid
else
using terms from application “Finder”
— no documents open. Here comes Finder …
set theFilePath to POSIX path of (target of window 1 as alias)
end using terms from
end if
end tell

— Now open in iTerm2
tell application “iTerm”
activate
set theTerm to (make new terminal)
tell theTerm
— set size
set number of columns to 132
set number of rows to 50
— launch a default shell in a new tab in the same terminal
launch session “Default Session”
tell the last session
— cd to the directory
write text “cd ” & theFilePath
end tell
end tell
end tell
{% endhighlight %}

I love tags. I want to use them more (I am a lazy ass), because when I use them I find myself finding the stuff I look for way easier. I use Tags and DefaultFolderX mainly for tagging, but when I am on the commandline (like most of the times) I always find it annoying to either use Tags or something else to add/remove/list tags.

That’s why I wrote this little script to help me tagging my files/folders. It needs openmeta and should be placed somewhere in your $PATH for easier access (obviously):

{% highlight bash %}
#!/usr/bin/env bash

#

Frontend script for the openmeta commandline utility

#

function usage {
echo “Usage:”
echo “$0 [file|directory]”
echo
echo “Specify one tag per line to add a tag, prepend a ‘-‘ to remove a tag”
exit 0
}

timestamp=$(date +%s)
dir=$1
qdir=$PWD/$1

openmeta -t -p $qdir | rev | cut -d” ” -f 2- | rev >/var/tmp/tag_$timestamp 2>/dev/null
if [ $? -ne 133 ]; then
curtags=$(cat /var/tmp/tag_$timestamp)
echo “Current tags: $curtags”
echo
fi

Exit if we have nothing to tag

[ ! -d $qdir -a ! -f $qdir ] && usage

while read -p “Tag: ” line
do
[ -z “${line:-}” ] && break
if [ “${line:0:1}” == “-” ]; then
rmtags=”$rmtags ${line:1}”
else
newtags=”$newtags $line”
fi
done

echo
if [ “$rmtags” == “” ]; then
openmeta -a ${newtags} -p $qdir | rev | cut -d” ” -f 2- | rev
else
for rmtag in $rmtags; do
curtags=$(echo $curtags | sed “s/$rmtag//g”)
done
openmeta -s ${curtags} ${newtags} -p $qdir | rev | cut -d” ” -f 2- | rev
fi

rm -f /var/tmp/tag_$timestamp &>/dev/null
{% endhighlight %}

I just tried to use X11 Forwarding from a RedHat 6 box to my Mac failing miserably.

You have to make sure to have the xorg-x11-xauth.x86_64 package installed on the RedHat box in order for MacOS to start the tunnel for X11 forwarding – otherwise it won’t work …

See the logs:

{% highlight bash %}
debug1: Requesting X11 forwarding with authentication spoofing.

debug1: Remote: No xauth program; cannot forward with spoofing.
{% endhighlight %}

After that X11 forwarding works like a charm :)

I recently faced the challenge (yes, it’s a challenge) to connect to an 802.1X secured network from Mac OS 10.7. While normally the people responsible should provide you with a configuration profile for your Mac, that’s actually not very often the case …

After trying to connect, installing certificates into my Keychain, I ended up with the following thread on the Apple Support Community:

https://discussions.apple.com/message/16164097#16164097

The answer of DrVenture pretty much explains the procedure, but I’d like to outline it here as well:

  1. Download iPCU (iPhone Configuration Utility) from here
  2. Open iPCU from Applications / Utilities or via Finder
  3. You screen will look like this:
  4. Select Configuration Profiles from the pane on the lefthand side
  5. Click on New
  6. Enter some required values in the General section
  7. Select the Credentials section
  8. Click on Configure and select your network certificate (I used a base64 encoded certificate)
  9. Now go back to the Wi-Fi section (never mind, Wi-Fi works for both wireless and cable connection)
  10. Now create a new Configuration. For a cable connection, specify any name as SSID, for a wireless connection – obviously – specify the correct SSID
  11. Now select the protocols you need to use. In my case it was TTLS and PEAP with MSCHAPv2 authentication
  12. Move on to the Authentication tab and put in your username and password (if needed). In case you need to present a certificate, go back to step 8 and import your private key for this certificate. You should be able to select it in the dropdown underneath the Password field.
  13. Last but not least navigate to the Trust tab and activate the checkbox next to your network certificate you have to trust.
  14. After you’ve done all that, you click on Export
  15. In the Export Configuration Profile dialog you select None as security and proceed by clicking Export …
  16. In the next dialog you just save the file somewhere on your harddisk
  17. To import the configuration profile, just double-click the file from finder.

Whenever you connect a network cable, a dialog should pop up asking you for the configuration profile to use. Just select the name you specified earlier and click OK. You can check the status of your 802.1X connection from the Network Preferences, allowing you to Connect, Disconnect and view some stats.

Hope it’s helpful for anyone :)

I recently got a Mac from my employer, and I’d like to try using Outlook 2011 for Mac. That, however, requires all my emails from Thunderbird to be transferred to Outlook 2011. After barely clinging onto sanity trying to migrate, I finally found the following article which brought me (at least halfway) there:

http://www.frontendeveloper.com/thunderbird_outlook/

However, the App mentioned to change the creator- and type-codes is only running on Rosetta (which of course isn’t available on Lion). I exchanged FileType to the (not nearly as comfortable, but at least working) app called Quick Change. You will have to use the following codes:

  • Creator: ttxt
  • Type: TEXT

After that, and, renaming the files to mbx, I was able to import my mails into Outlook 2011.