Clear Memory in Linux Box

Clear Memory in Linux (specially for squid servers)
If you are hosting SQUID proxy server on your Linux box, you may have noticed that SQUID as a proxy server is very greedy with memory. Over the period of time, it consumes large amount of memory , even in some cases 98-99%. This script will clear the memory so that it be used by system or SQ I! again. "a#e sure you are logged in with root user in order to continue. $ust create a new script and put it in any folder li#e %temp &reate 'ile by following command

1 2 3 4 5 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

mkdir /temp cd /temp touch touch /var/log/cron.log chmod +x
(ow edit the file by

nano /temp/
.)nd *aste the following code.

#!/bin/bash # Clear/Dump Cache Memory, to increase ree memory, use ul or !"#$D proxy %& or # !yed 'ahan(aib / )mail* ,eb* http*// # Make sure you are .ogged in -ith user root. # !etting variables or script set /0date1 time23date 4a-k 56print /7853 # 9ction . . . sync: echo ; < /proc/sys/vm/drop=caches

# 9dd entry in /var/log/cron.log to make record. echo >'(? Cache Memory Clear, 9ction .ogged at /@A/BA/; /time < /var/log/cron.log

.Save, and Exit. (ow change the permission so it can be executed.


chmod CDD /temp/

sh .)nd you will see the changes before and after running the file clearmem.(ow paste following code + @dail /temp/clearmem. So to ma#e all memory ! Enable this i' o# (ant to r#n the script on ho#rl basis (ow. . open terminal. based on above selection.ob will run this command at selected scheduled timings and clear any memory cache (ow some /xplanation of what above script do . causing that memory to become free.(ow first execute 1 ree Am and note down the free ! "#n Dail in ni$ht at %%&%% ho#rs ! @ho#rl /temp/clearmem.if it as#s for text editor. dentries and inodes from memory. ) drop*caches doesn0t touch dirty caches and only drops clean caches. select nano .sh chec# the log file by cat %var%log%cron. . (ow execute the file by running + /temp/ sure you are logged in with the root user. cron . . . type crontab -e . it is necessary to do sync first before drop*caches in case flushing daemons hasn0t written the changes to dis#.Howto schedule this file to run daily/hourly using ‘crontab’ To run this file on hourly basis. This is in generally a non1destructive operation.log (ow again chec# the free amount from terminal with the command 1 ree Am . It will cause the #ernel to drop clean caches. cache is still preserved. ) s nc only ma#es dirty cache to clean cache.