Indonesian Back|Track Team
Share Auto Clear Cache Memory for VPS / DS - Printable Version

+- Indonesian Back|Track Team (https://www.indonesianbacktrack.or.id/forum)
+-- Forum: General Zone (https://www.indonesianbacktrack.or.id/forum/forum-172.html)
+--- Forum: Programming (https://www.indonesianbacktrack.or.id/forum/forum-95.html)
+---- Forum: Bash (sh) (https://www.indonesianbacktrack.or.id/forum/forum-96.html)
+---- Thread: Share Auto Clear Cache Memory for VPS / DS (/thread-5674.html)

Pages: 1 2


Auto Clear Cache Memory for VPS / DS - Junior Riau - 03-15-2014

Assalamualaikum wr wb
hai hai Big Grin apa kabar =))
saya nongol lagi nih wkwkwk

kali ini mau share sedikit script kecil kecilan yang saya pake di server sendiri. fungsinya buat clear cache ram yang udah penuh
langsung saja cekidot

[hide]
ini scriptnya, silahkan dimanipulasi sesuai kebutuhan,
pastikan direktori freecache ada di /var/log/
atau bisa sesuaikan sendiri
Code:
#!/bin/sh
##
###################################################################
###########    Original Script Code by Junior Riau    ###########
###################################################################

#####Define minimum free memory#####
MIN=1024

#####Getting current free memory#####
FREE=$(free -m | grep Mem | awk '{print $4}')
USE=$(free -m | grep Mem | awk '{print $3}')
DIRLOG="/var/log/freecache"
TIME=$(date +"%d-%m-%Y-%H-%M-%S")

#####Checking current free memory is bigger than minimum memory#####
if [ $FREE -lt $MIN ]; then

    #####Save log into file####
    LOGFILE="$DIRLOG/log-$TIME.log"
    echo "+++++++++++++++++++++++++" > $LOGFILE
    echo "Memory Info" >> $LOGFILE
    echo "Use memory : $USE" >> $LOGFILE
    echo "Free Memory : $FREE" >> $LOGFILE
    echo "\n" >> $LOGFILE
    echo "After Clear Cache" >> $LOGFILE
    echo 1 > /proc/sys/vm/drop_caches
    sleep 2
    echo 0 > /proc/sys/vm/drop_caches
    echo "Use memory : $(free -m | grep Mem | awk '{print $3}')" >> $LOGFILE
    echo "Free Memory : $(free -m | grep Mem | awk '{print $4}')" >> $LOGFILE
    echo "+++++++++++++++++++++++++" >> $LOGFILE
else
    sleep 1
    exit 0
fi
sleep 1
exit 0

NOTE :
Tested Only on :
  1. Centos
  2. Cloud Linux

silahkan sesuaikan dengan system cache os masing masing


untuk lebih efektif masukkan ke cronjob server dengan cara

Code:
crontab -e

0 0,3,6,9,12,15,18,21 * * * /path/to/script.sh

itu waktu script berjalan setiap 3 jam sekali, diatur saja sesuai keinginan, maaf kelupaan kemaren
semoga bermanfaat
[/hide]

Best Regards

Junior Riau


RE: Auto Clear Cache Memory for VPS / DS - abdilahrf - 03-15-2014

mantap om (Y) .. tapi hidenya fail wkowkwo :v


RE: Auto Clear Cache Memory for VPS / DS - Junior Riau - 03-15-2014

hahaha sudah dibenerin itu hidenya


RE: Auto Clear Cache Memory for VPS / DS - hamdan_zenith - 03-15-2014

mantap om,, wkwkwkwk benar yg di katakan om @abdilahrf Big Grin wkwkwkwkwk gak berhasil di hide Big Grin

oiya om,, ane mau nanya, ini berlaku juga utk clear cache dari proxy ?? Smile


RE: Auto Clear Cache Memory for VPS / DS - Junior Riau - 03-15-2014

itu kan vm=virtual memory, untuk proxy tinggal arahin ke drop cachenya proxy Smile


RE: Auto Clear Cache Memory for VPS / DS - THJC - 03-15-2014

Tes ah di ubuntu.. Smile


RE: Auto Clear Cache Memory for VPS / DS - Junior Riau - 03-15-2014

kalau ubuntu
adanya echo 1, 2 atau 3, echo 0 gak ada, jadi disesuaikan sama os nya


RE: Auto Clear Cache Memory for VPS / DS - hamdan_zenith - 03-15-2014

(03-15-2014, 08:31 PM)junior.riau18 Wrote: itu kan vm=virtual memory, untuk proxy tinggal arahin ke drop cachenya proxy Smile

maaf double post tadi kepencet Big Grin hahaha

iyaa om,, saya coba dulu om,, hehe soalnya baru belajar cache squid proxy Smile

thanks yaa om. Smile


RE: Auto Clear Cache Memory for VPS / DS - mas~jojoen - 03-16-2014

cobba dulu pak di server vps jualan ssh .. Big Grin


RE: Auto Clear Cache Memory for VPS / DS - Junior Riau - 03-16-2014

(03-16-2014, 02:50 AM)mas~jojoen Wrote: cobba dulu pak di server vps jualan ssh .. Big Grin

disesuaikan dulu pak,, untuk debian saya g taw ada echo 0 atau tidak, kalau ubuntu echo 1 atau 2 atau 3,, centos rhel echo 0 ada,,