Find the answer to your Linux question:
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 ...
  1. #1
    Just 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,
    1. parse fdisk's output to see what drives and partitions I've got
    2. parse the kernel buffer to see how each device entry relates to a SCSI descriptor
    3. parse /proc/scsi/scsi by descriptor to get the human readable model name for the disk
    4. 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./
    Attached Files Attached Files

  2. #2
    Linux 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?

  3. #3
    Just 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.

  4. #4
    Linux Guru
    Join Date
    May 2011
    Posts
    1,843
    Quote Originally Posted by ianatkin
    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.
    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.

    This command will look for the 'model' file and show its contents, for all hard disks found on your system:

    Code:
    grep -H . /sys/block/[sh]d*/device/model
    You can use udevadm (or udevinfo, depending on your system) to query the /sys filesystem, e.g.:

    Code:
    udevadm info --query=all --name=/dev/sda

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...