Thursday, May 12, 2011

Automate Swap Memory Actions Scripts

What is the Most Important for Our Server?
I think it is the Swap Memory!
If all of the physical memory space used by programs, the Kernel begin to use Swap to allocate more memory.
If all of the swap already in use, the server (or computer) will hang and needs to reboots automatically!!!
Let me share this simple script, just put it in Crontab every 5 minutes to runs automatically in the background.
Cheers!!!

#Start Script
#!/bin/bash


SERVER=`hostname`


DATE=`date +%Y%m%d_%H%M`


swap=`free -m | awk -F" " '{print $3}' | tail -1`
echo "SWAP Used NOW = $swap";
limit=1000


if [ $swap -gt $limit ];


then


        #This is the Actions if Limit reached
        /etc/init.d/httpd reload;


        echo "$SERVER Swap Memory Warning!";


else


        echo "Swap still safe now.."


fi


#End of Script


Save the script anywhere in the Server, and don't forget to add "chmod +x <your_script>.sh"

Author : IndraSusanto

If you found this script useful, dont forget to leave some comments :)

No comments:

Post a Comment