Sandra Schlichting
Sandra Schlichting

Reputation: 25996

Extracting info from hdparm output

If you run hdparm -I /dev/X where X is your SSD device, it would print info (read-only operation) something similar to this

...
Security: 
    Master password revision code = 36401
        supported
    not enabled
        locked
    not frozen
        expired: security count
        supported: enhanced erase
...

So it should be easy to extract the not in front of frozen with

for d in $(ls /sys/block); do
    is_frozen=$(hdparm -I /dev/$d | awk '/frozen/ { print $1 }')
    echo $is_frozen
done

However it always return frozen as if not isn't there.

Question

Can someone explain how to extract the not from the frozen line?

Upvotes: 1

Views: 1159

Answers (2)

Miles
Miles

Reputation: 677

On my system, /dev/sda is currently frozen and /dev/sdb is not frozen, as seen here:

# hdparm -I /dev/sda | grep frozen
        frozen
# hdparm -I /dev/sdb | grep frozen
    not    frozen

Just add $d to your echo command to see the device and its correct corresponding value (I took the liberty of replacing the lengthy awk command with a much shorter grep):

# for d in $(ls /sys/block) ; do is_frozen=$(hdparm -I /dev/$d | grep frozen) ; echo $d $is_frozen ; done
 HDIO_DRIVE_CMD(identify) failed: Invalid argument
loop0
...
sda frozen
sdb not frozen

If you'd like to cleanup the output, replace ls with find:

# for d in $(find /sys/block -name 'sd*' -exec basename {} \;) ; do is_frozen=$(hdparm -I /dev/$d | grep frozen) ; echo $d $is_frozen ; done
sda frozen
sdb not frozen

or have ls query /dev/sd? instead:

# for d in $(ls -1 /dev/sd?) ; do is_frozen=$(hdparm -I $d | grep frozen) ; echo $d $is_frozen ; done
/dev/sda frozen
/dev/sdb not frozen

Upvotes: 1

Gautam
Gautam

Reputation: 1932

One possible reason may be that what you see on screen is not the result of awk, but of stderr. Here's what you can do to diagnose it :

  1. Forego the for loop for now and test with one device, say sda.
  2. Redirect the output to a file, e.g. $ sudo hdparm -I /dev/sda > /tmp/tempfile
  3. See if you still see the lines with 'frozen' no screen.

Upvotes: 1

Related Questions