Saturday, June 20, 2015

Calculate memory information

# cat  free_mem.ksh

#!/usr/bin/ksh
# Calculate memory information on your system.
 #
# Checking available memory
memory=`prtconf | grep Memory | head -1 | awk 'BEGIN {FS=" "} {print $3}'`
gb_memory=`echo $memory/1024 | bc -l`
#
# Checking Free memory
 pagesize=`pagesize`
 kb_pagesize=`echo $pagesize/1024 | bc -l`
 sar_freemem=`sar -r 1 1 | tail -1 | awk 'BEGIN {FS=" "} {print $2}'`
 gb_freemem=`echo $kb_pagesize*$sar_freemem/1024/1024 | bc -l`
#
# Checking Used Memory
 gb_usedmem=`echo $gb_memory-$gb_freemem | bc -l`
#
#  Display statistics
 echo "Avaiable Memory: $gb_memory GB"
 echo "Free Memory: $gb_freemem GB"
 echo "Used Memory: $gb_usedmem GB"
# EOF ##

No comments:

Post a Comment