I am trying to find out whether disk is SSD or HDD using bash script.
logical_name="/dev/sda"
type=""
disk=$(basename $logical_name)
x=`cat $filename | grep "${disk}" | awk '{print $2}'`
if [ ! -z "$x" ]
then
if [ "$x" = "0" ]
then
type="SSD"
fi
if [ "$x" = "1" ]
then
type="HDD"
fi
fi
echo $type
Value of x is correct, 0 or 1. But after comparison, it's not assigning any value to variable type
. It prints as empty. Can anyone point out what am I doing wrong here?
More information:
$filename is a file that contains output of sudo lsblk -d -o name,rota
NAME ROTA
sda 1
sdd 1
sdc 0