Home > Linux > Unix shell scripts – Display Total, Used and Free Memory

Unix shell scripts – Display Total, Used and Free Memory

August 18th, 2010 Leave a comment Go to comments

Bash script berikut akan menampilkan total memori yang digunakan dan yang tidak digunakan.
Buat file menggunakan editor dan simpan dengan nama mem.sh
Berikut source code-nya:

#! /bin/bash
# Total memory space details

echo "Memory Space Details"
free -t -m | grep "Total" | awk '{ print "Total Memory space : "$2 " MB";
print "Used Memory Space : "$3" MB";
print "Free Memory : "$4" MB";
}'

echo "Swap memory Details"
free -t -m | grep "Swap" | awk '{ print "Total Swap space : "$2 " MB";
print "Used Swap Space : "$3" MB";
print "Free Swap : "$4" MB";
}'

Jalankan file : ./mem.sh

$ ./mem.sh
Memory Space Details
Total Memory space : 1000 MB
Used Memory Space : 31 MB
Free Memory : 968 MB
Swap memory Details
Total Swap space : 0 MB
Used Swap Space : 0 MB
Free Swap : 0 MB
Categories: Linux Tags:
  1. No comments yet.
  1. No trackbacks yet.

*

Bad Behavior has blocked 251 access attempts in the last 7 days.