Results 1 to 4 of 4
Hi,
I've been working on a bash script for use in a lightweight Linux environment for computer imaging. The intention is to display to the user a selection dialog for ...
- 01-06-2012 #1Just Joined!
- Join Date
- Jan 2009
- Posts
- 3
Script to ennumerate drives, partitions, disk usage
Hi,
I've been working on a bash script for use in a lightweight Linux environment for computer imaging. The intention is to display to the user a selection dialog for attached disks with partition data to help them make the right decision when it comes to wiping a computer's disk.....
The tack I've taken is to,
- parse fdisk's output to see what drives and partitions I've got
- parse the kernel buffer to see how each device entry relates to a SCSI descriptor
- parse /proc/scsi/scsi by descriptor to get the human readable model name for the disk
- temporarily mount each partition and use df to determine the drive usage
It's not very elegant, and I dislike my need to parse the kmsg buffer as the data I need in there will eventually rotate out into oblivion.
I've attached the script. I think it needs a critical eye..... I am certain my approach is not optimal....
Kind Regards,
Ian./
- 01-07-2012 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
I don't have any SCSI disks currently available to me to confirm this, but aren't a lot of those things you are looking for available via the /sys filesystem?
Also, in your script, you use /dev/nul, do you mean /dev/null?
- 01-07-2012 #3Just Joined!
- Join Date
- Jan 2009
- Posts
- 3
yes and yes!! Big thanks.
I'd never looked through the /sys/block filesystem before, and there is tonnes of stuff there. We've got a direct link between the scsi device (\dev\sda etc) and descriptor, the model data, the removable flag... Brilliant.
The script is revised now, and is much, much simpler. Even better is that it works entirely off live data and not the historical dmesg info. Can't believe now all the extra effort I had to go to in parsing dmesg and /proc/scsi/scsi (although that challenge did teach me a couple of things).
Here is the revision,
DiskInfo_v1.1.sh.txt
Atreyu -what does /sys/block look like for IDE devices? Is there still a model entry in there? I don't have an machine with IDE to test on.... but would like this in the end to work for both SCSI and IDE drives.
- 01-07-2012 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
True parallel IDE hard drives are hd*, so the block devices are /dev/hd* and the are found in /sys/block/hd*. SATA drives are seen as sd* drives, so they are /dev/sd* in /sys/block/sd*, like SCSI drives.
Originally Posted by ianatkin
This command will look for the 'model' file and show its contents, for all hard disks found on your system:
You can use udevadm (or udevinfo, depending on your system) to query the /sys filesystem, e.g.:Code:grep -H . /sys/block/[sh]d*/device/model
Code:udevadm info --query=all --name=/dev/sda


Reply With Quote