nxhelp.com

Match VMware Disk to Linux Device

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:

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 …)

Automatically Set Hostname From DHCP in Debian Using Isc-dhcp-client

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:

(hostname) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/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...

Thank you!

Calculating Sums Using Awk

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:

cat something | awk '{ SUM += $5} END { print SUM }'

Thank you!

Command-Line Openmeta Tagging on MacOS

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):

#!/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

X11 Forwarding to a Mac

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:

debug1: Requesting X11 forwarding with authentication spoofing.
...
debug1: Remote: No xauth program; cannot forward with spoofing.

After that X11 forwarding works like a charm :)

Connecting to an 802.1X Network on Mac OS 10.7 Lion

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:

  1. Select Configuration Profiles from the pane on the lefthand side

  1. Click on New

  1. Enter some required values in the General section

  1. Select the Credentials section

  1. Click on Configure and select your network certificate (I used a base64 encoded certificate)

  1. Now go back to the Wi-Fi section (never mind, Wi-Fi works for both wireless and cable connection)

  1. Now create a new Configuration. For a cable connection, specify any name as SSID, for a wireless connection - obviously - specify the correct SSID

  1. Now select the protocols you need to use. In my case it was TTLS and PEAP with MSCHAPv2 authentication

  1. 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.

  1. Last but not least navigate to the Trust tab and activate the checkbox next to your network certificate you have to trust.

  1. After you’ve done all that, you click on Export

  1. In the Export Configuration Profile dialog you select None as security and proceed by clicking Export …

  1. In the next dialog you just save the file somewhere on your harddisk

  2. 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 :)

Import Mail From Thunderbird to Outlook 2011 on Mac

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.

Prevent File Deletion on Linux

Note to self, before I google it another 25 times … Here’s how to prevent a file to be deleted using extended attributes on Linux:

chattr +i <file>

to check if it worked:

lsattr <file>

example:

$> sudo chattr +i testfile
    $> lsattr testfile
    ----i------------e- testfile

Finding Only Parent PIDs

Having a process that spawns children of itself it can be hard to only find the parents … this command is pretty weird looking, but actually works. You can achieve the same much easier if you want to use ‘ps -ef | grep …’, but I wanted to stick with pgrep, so:

pgrep boe_crprocd.bin | egrep -v "$(pgrep boe_crprocd.bin -P "$(pgrep boe_crprocd.bin -d ",")" -d "|")"

Connecting to a Remote DB2 Instance

Preparing the DB2 Client

On Windows

After the initial installation, to be able to connect using the command line, just run:

db2cmd -i -w db2clpsetcp

On Unix

Source the db2profile

. $HOME/sqllib/db2profile

Accessing a Remote Database

To be able to access a remote database you have to catalog the node and the database.

db2 "catalog tcpip node remote remote remotehost server 50000"
db2 "catalog database testdb as remotedb at node remote authentication server"

As an example for our internal DB2 test instance:

db2 "catalog tcpip node usphlesx remote usphlesxcab04.pgdev.sap.corp server 50000"
db2 "catalog database sample as cab04smp at node usphlesx"

Once you did that, you can list the open catalogs:

-
db2 "list node directory"
db2 "list database directory"

To uncatalog the node/database run:

db2 "uncatalog database remotedb"
db2 "uncatalog node remote"
Further reading