Solaris diskspace calculation in Megabytes

04 Nov

Someone asked me how they can compute the diskspace (used/available) in Megabytes. The goal is to get the info in Megabytes only and report it, so that other programs can make use of it in automation.

As a backdrop – the df command in Solaris supports the -k switch, which computes the diskspace in kilobytes. Unlike linux, which supports switches for human readable formats (-h) and blocksize switch (-B), the df command in Solaris has limited number of switches.

Here is a small code snippet that can get you the file system utilization (for a given file system – in this case /) in Megabytes.

 

$ df -k / | tail -1 | awk ‘{ print $1, $2/1024, $3/1024, $4/1024, $5, $6 } ‘

rpool/ROOT/solaris-161 476612 230165 246197 49% /

$

 

The idea is to grab the kilobyte numbers and divide them by 1024. Depending on your need, this snippet can be further improved to display the output in various formats (like sizes in GB or drop some fields.)

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.