Sunday, June 8, 2014

Bash Script to determine capacity of a SCSI device


Please use above script to determine the capacity or device size of your SCSI device like Hard Disk (sda) or CD-ROM (sr0).
Copy the script into a script file e.g readcap.sh and run as below:

./readcap /dev/sda

Above command determines capacity of Hard Disk.

Script:

#This script display the SCSI device capacity you are quering about !!
#e.g. usage: ./readcap /dev/sda
#!/bin/bash
ls $1 2>/dev/null 1>/dev/null
if [ $(echo $?) -eq 0 ]
then
sudo sg_readcap  $1 | tail -1 | awk 'BEGIN{ORS ="";print "SCSI Device Capacity: "}{print $7;ORS="\n"}END{print " GB"}'
else
echo "Wrong SCSI device entered/Incorrect usage of script"
fi

Guys please report me back any issues found during script execution.

No comments:

Post a Comment