Server Memory Usage Bash Script

back to tech articles
Linux, Terminal

I wanted a simple script to show me the memory usage on my CentOS 6 server so we could monitor peak traffic and usages.

This is easily configured but very useful. Just call the script using cron and make sure it is executable! I call it every hour and overwrite it every week, simple and useful.

1
2
3
4
5
6
7
8
9
#!/bin/bash

memt=$(free -m /proc/meminfo)
curt=$(date +%a" "%b" "%d" "%Y" "%T)

echo ":: Memory Usage at $curt:
$memt

"

Make sure your script is executable and probably put it in your path.

1
/usr/local/bin/

Make the script executable.

1
$ chomd +x /usr/local/bin/freemem.sh

Feel free to share any improvements of your own.