You are currently browsing the tag archive for the ‘Linux’ tag.

If you followed my wmic post a while back you’ll have seen that wmic outputs a LARGE amount of data seperated by the | character, sort of like a CSV. This quickly becomes unusable as the first line is the column titles of the data and each following line is a result. So I wrote a small, very much ugly and not exactly rock solid, bit of python to dump wmic output into a Dictionary of Lists. What I mean is every column will be a key in the Dictionary and each value is a list of 1 or more values. So for instance a WMI query of HDDs will likely return 2+ (Your C Drive and a CD Drive), but say one for memory will only return one. Anyway this is pretty basic and doesn’t do much more than print the actual dictionary but it might help someone write a Cacti plugin or a Nagios plugin that can pull free disk space for example.

Here it is: pythonwmic (Yes Sorry it’s called .doc but wordpress doesn’t seem to like .py)

To use it just call the script (first modifying the win32User/Password variables) with one argument which is the IP address of the server you want to query. Bear in mind it’s fairly rough but hopefully enough to get you going. It doesn’t work for all WML queries but the Win32_PerfFormattedData_ ones seem to work nicely (Win32_OperatingSystem I’m looking at you inparticular with your extra | characters in the Name column !).

As an example of output I ran against one of my machines querying the Logical Disks:

{‘DiskBytesPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Frequency_Sys100NS’: [‘0’, ‘0’, ‘0’, ‘0’], ‘PercentDiskReadTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Timestamp_Object’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskBytesPerTransfer’: [‘0’, ‘0’, ‘0’, ‘0’], ‘PercentIdleTime’: [‘100’, ‘100’, ‘100’, ‘100’], ‘AvgDiskBytesPerWrite’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Description’: [‘(null)’, ‘(null)’, ‘(null)’, ‘(null)’], ‘DiskWriteBytesPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Timestamp_Sys100NS’: [‘0’, ‘0’, ‘0’, ‘0’], ‘DiskWritesPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘PercentDiskTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskQueueLength’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskBytesPerRead’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDisksecPerRead’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Timestamp_PerfTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Name’: [‘C:’, ‘E:’, ‘F:’, ‘_Total’], ‘CurrentDiskQueueLength’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDisksecPerWrite’: [‘0’, ‘0’, ‘0’, ‘0’], ‘DiskReadBytesPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Caption’: [‘(null)’, ‘(null)’, ‘(null)’, ‘(null)’], ‘PercentDiskWriteTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Frequency_Object’: [‘0’, ‘0’, ‘0’, ‘0’], ‘Frequency_PerfTime’: [‘0’, ‘0’, ‘0’, ‘0’], ‘SplitIOPerSec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskReadQueueLength’: [‘0’, ‘0’, ‘0’, ‘0’], ‘FreeMegabytes’: [‘54155’, ‘127668’, ‘69809’, ‘251632’], ‘DiskReadsPersec’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDiskWriteQueueLength’: [‘0’, ‘0’, ‘0’, ‘0’], ‘AvgDisksecPerTransfer’: [‘0’, ‘0’, ‘0’, ‘0’], ‘PercentFreeSpace’: [’77’, ’91’, ’99’, ’90’], ‘DiskTransfersPersec’: [‘0’, ‘0’, ‘0’, ‘0’]}

Have fun, and please post comments, corrections or improvements ! I’m sure there’s better/more_pythonistic ways to build the Dictionary and I will at some stage build a better way to output key bits of data rather than just dump the dictionary as is possibly with a Cacti/Nagios plugin to utilise it.


Last week I found a truly excellent tool for adding, modifying and managing user in Active Directory from Linux. It’s in Ubuntu

sudo aptitude install adtool

For a better guide in setting it up Vide has a great one over at his site.

One thing that got me though, you have to make sure your /etc/ldap/ldap.conf file is set up correctly, which should have been obvious but it stumped me for a while (necessary to allow setting passwords etc.)

Make sure you have the following in your config:

BASE    dc=ad-servername,dc=example,dc=com
URI     ldaps://

This allows you to correctly receive the SSL certificate from the server, otherwise you’ll get an error like this:

bind: : Can’t contact LDAP server (-1)

And hey presto you can avoid using MMC to manage users. 🙂 And if you combine it with wmic ….. happy days !

sudo aptitude install wmi-client

Example of usage is;

wmic -U DOMAIN/administrator%password // “Select * from Win32_Service”

Lists all services, the first line it spits back is the fields which you can use this SQL like language  to filter, so to see only the names of the services installed we’d do:

wmic -U DOMAIN/administrator%password // “Select Name from Win32_Service”

Or Name and State:

wmic -U DOMAIN/administrator%password // “Select Name,State from Win32_Service”

Or for just one service in this case the UPS service:

wmic -U DOMAIN/administrator%password // “Select Name,State from Win32_Service where name=’UPS'”

The language for the queries is called WQL and a reference is available here over at MSDN.

Hope this helps, this is only in Hardy as far as I’m aware.

WARNING: Before doing this bear in mind that if your laptop explodes in a cloud of molten plastic and silicon that I warned you and I take no responsibility… so don’t blame me ! 😉

A Friend of mine was running CentOS on a Thinkpad T43 (this should work on all though) and the fan was running but apparently not enough to stop the laptop dying after a hour or so. Sounds like a hardware issue, but nonetheless here’s a wee hack to get it to run in Maximum Fan Mode and so far has done the trick.

There is a kernel module in CentOS 5 called ibm_acpi, it needs to be loaded with experimental features, so easiest way to do this is to edit (or create, he didn’t have the file initially, so open in vi/nano etc.)


And add the line;

modprobe ibm_acpi experimental=1

This will load the module each time in experimental mode. Dont’ forget to

chmod +x /etc/rc.modules

If it didn’t exist as it’s a script that needs to be run so has to have execute permissions. Next use an editor to open up /etc/rc.local and add the following line to it;

echo 0x2F 0x40 > /proc/acpi/ibm/ecdump

When the laptop reboots it’ll load the ibm_acpi module creating a new directory in /proc containing special files, for instance the fan info file located at /proc/acpi/ibm/fan (you can cat this file and it’ll list the fans RPM and what mode it is in).

What the echo command we entered in ecdump does is switch the fan into “disengaged” mode, which basically tells it to not bother with auto sensing when it should turn on and run in full speed mode instead, which is around the 6000rpm mark as opposed to 3000rpm in normal mode. so in this new disengaged mode you’ll get something like this from using cat on /proc/acpi/ibm/fan

status:         disabled
speed:          6357
commands:       enable, disable

Yes it does say disabled but that’s it’s disengaged mode. If at any point you want to temporarily go back to auto just do the following;

echo 0x2F 0x80 > /proc/acpi/ibm/ecdump

And to permanently leave it in auto mode just remove that line from /etc/rc.local

Hope this helps someone out and it should be relativly simple to port to other distros. Bear in mind that after kernel 2.6.22 ibm_acpi no longer exists and totally new functionality has been built in a thinkpad module, but for more info best off looking on the thinkpad wiki site at:

ThinkPad Wiki

Edit To Add Other Mode Available:

#(fan off – DONT DO THIS !!)

echo 0x2F 0x00 > /proc/acpi/ibm/ecdump

#(low speed)

echo 0x2F 0x02 > /proc/acpi/ibm/ecdump

#(medium speed)

echo 0x2F 0x04 > /proc/acpi/ibm/ecdump

# (maximum speed)

echo 0x2F 0x07 > /proc/acpi/ibm/ecdump

#(automatic – default)

echo 0x2F 0x80 > /proc/acpi/ibm/ecdump


echo 0x2F 0x40 > /proc/acpi/ibm/ecdump

Very quick note, just found a link to get Skype’s API integrated into Kontact so a simple click on a phone number in Kontact’s address book activates Skype. Very Cool ! 🙂

I made one minor change as I have already formatted my KDE numbers to have a plus. Just change this line if you have also:

number = ‘+’ + sys.argv[1]


number = sys.argv[1]

I might tweak this a bit to do it automagically… but then again maybe I won’t get around to it 😉