Thursday, January 10, 2008

Memory usage report for Unix system

Following simple script will generate the report of memory usage on unix system. It will store user memory, system memory and total memory consumption numbers in the report file, mem_stat.txt

##### SCRIPT BEGIN ########
#!/bin/sh

rm -rf /tmp/mem_stat.txt
top -f /tmp/mem.txt

while [ 1 ]
do
top -f /tmp/mem.txt;
grep Memory /tmp/mem.txt awk -F" " '{print $2,$5,$8}' sed -e 's/K//g' >> /tmp/mem_stat.txt;
rm -f /tmp/mem.txt;
sleep 30;
done>> /tmp/mem_stat.txt;
rm -f /tmp/mem.txt

########SCRIPT END#########