手动清除内存shell【root权限】

#!/bin/bash

#1.system environment variables

cd ~

. ./.bash_profile

#2.define variables

v_freenum=`free -m | sed -e '1d' -e '3d' -e '4d' | awk '{print $4}'`;

v_logpath="/home/webuser/wyk/shell/log";

v_definenum=90;#定义单位M

#if begin

if [[ ${v_freenum} -le ${v_definenum} ]]

then

 sync;sync;sync;

 echo 1 > /proc/sys/vm/drop_caches;

 date >> ${v_logpath}/Free_cache.log;

 cat /proc/sys/vm/drop_caches >> ${v_logpath}/Free_cache.log;

 v_freenum=`free -m | sed -e '1d' -e '3d' -e '4d' | awk '{print $4}'`;

 if [[ ${v_freenum} -gt ${v_definenum} ]]

 then

    sync;sync;sync;

   echo 0 > /proc/sys/vm/drop_caches;

  else

   sync;sync;sync;

   echo 2 > /proc/sys/vm/drop_caches;

   date >> ${v_logpath}/Free_cache.log;

   cat /proc/sys/vm/drop_caches >> ${v_logpath}/Free_cache.log;

  v_freenum=`free -m | sed -e '1d' -e '3d' -e '4d' | awk '{print $4}'`;

  if [[ ${v_freenum} -gt ${v_definenum} ]]

  then

     sync;sync;sync;

    echo 0 > /proc/sys/vm/drop_caches;

   else

    sync;sync;sync;

    echo 3 > /proc/sys/vm/drop_caches;

    date >> ${v_logpath}/Free_cache.log;

    cat /proc/sys/vm/drop_caches >> ${v_logpath}/Free_cache.log;

    sync;sync;sync;

    echo 0 > /proc/sys/vm/drop_caches;

  fi

 fi

fi

#if end


你可能感兴趣的:(手动清除内存shell【root权限】)