Simple Shell Script To Calculate Total Storage On a Linux Server

Lets face it. Linux doesn’t provide a very simple way to tell how many disks are attached to server. There is no simple way to know the total storage if you don’t have palimpsest tool installed, which is unlikely if you are accessing server through putty 😦

I was asked to check total storage available on the server & it was an overwhelming task since my server has 36 disks attached (of-course coming from SAN)!! So, I decided to write a shell script that would allow me to get all the details in one go 😉

Below is my script : –

DISKNUM=`fdisk -l | grep -e "^Disk /dev/sd" | wc -l`
while [ $i -le $DISKNUM ]
D=`fdisk -l | grep -e "^Disk /dev/sd" | awk '{print$3}' | cut -f1 -d, | head -$i | tail -1`
SUM=`python -c "print $DISK" | cut -f1 -d.`
let i=$i+1
echo "Total Disks Attached Are : $DISKNUM."
echo "Total Storage Attached is : $SUM GB or $TB TB."

Upon its execution, this is what I found as output.

[shashank@server ~]$ sudo sh
Total Disks Attached Are : 36.
Total Storage Attached is : 5411 GB or 5 TB.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s