Friday, December 26, 2008

Listing Storage Devices That Contain A File System

Here's a script that finds (using HAL) all the storage devices containing a file-system (except for optical discs) that are attached to a given machine, whether or not they are mounted:

#! /bin/bash
hal-find-by-property --key volume.fsusage --string filesystem |
while read udi ; do
# ignore optical discs
if [[ "$(hal-get-property --udi $udi --key volume.is_disc)" == "false" ]]; then
dev=$(hal-get-property --udi $udi --key block.device)
fs=$(hal-get-property --udi $udi --key volume.fstype)
echo $dev": "$fs
fi
done

This was my answer to a question on stackoverflow.com, during the few days that I thought that website was worth the time. I got over it.

(see a previous post of mine, for another example of stuff that can be done with HAL)

No comments:

Post a Comment