Thursday, May 12, 2011

Script to Automate Swap Memory Actions

What is the Most Important for Our Server?
I think it is the Swap Memory Monitoring!
If all of the physical memory space used by programs, Linux 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 reboot!!!



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, but 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