Script to save Ram
Hello Folks,
Today we are going to see a simple script to save Ram. We know Ram is the main part of the server resource. Most of the Ram is cached or bufferred, so we can use the following script to increase the Ram and server performance. You can set the cronjob as you wish. I recommend you to set it to every 10 minutes.
vim /root/ram.sh
#!/bin/bash temp=`free -m | grep "Mem:" | awk '{print $4}'` if (($temp < 300)); then /bin/sync; /bin/echo 3 > /proc/sys/vm/drop_caches; fi temp=`free -m | grep "Mem:" | awk '{print $4}'` if (($temp < 300)); then /bin/echo -e "\n===========\n`date`\nMemory less than 300M. Apache restarted \n===========\n"; /usr/sbin/service apache2 restart; fi
That’s all ……..!