[Share] Auto Clear Cache Memory for VPS / DS
#1
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

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

#3
hahaha sudah dibenerin itu hidenya

#4
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

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

#6
Tes ah di ubuntu.. Smile
Yang putih, yang seharusnya ber-aksi dan berbakat!
Linuxtivist blog

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

#8
(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

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

#10
(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,,






Users browsing this thread: 2 Guest(s)