-
-
Save Chaturaphut/422ef580240b9febdeb3d17d01c1db26 to your computer and use it in GitHub Desktop.
Revisions
-
pklaus revised this gist
May 31, 2013 . 1 changed file with 19 additions and 51 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,66 +1,34 @@ #!/bin/bash ## Bash Script to clear cached memory on (Ubuntu/Debian) Linux ## By Philipp Klaus ## see <http://blog.philippklaus.de/2011/02/clear-cached-memory-on-ubuntu/> if [ "$(whoami)" != "root" ] then echo "You have to run this script as Superuser!" exit 1 fi # Get Memory Information freemem_before=$(cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2) && freemem_before=$(echo "$freemem_before/1024.0" | bc) cachedmem_before=$(cat /proc/meminfo | grep "^Cached" | tr -s ' ' | cut -d ' ' -f2) && cachedmem_before=$(echo "$cachedmem_before/1024.0" | bc) # Output Information echo -e "This script will clear cached memory and free up your ram.\n\nAt the moment you have $cachedmem_before MiB cached and $freemem_before MiB free memory." # Test sync if [ "$?" != "0" ] then echo "Something went wrong, It's impossible to sync the filesystem." exit 1 fi # Clear Filesystem Buffer using "sync" and Clear Caches sync && echo 3 > /proc/sys/vm/drop_caches freemem_after=$(cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2) && freemem_after=$(echo "$freemem_after/1024.0" | bc) # Output Summary echo -e "This freed $(echo "$freemem_after - $freemem_before" | bc) MiB, so now you have $freemem_after MiB of free RAM." exit 0 -
pklaus revised this gist
May 12, 2011 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,8 +57,10 @@ if [ $root ]; then sync; else $sudo sync; fi if [ "$?" != "0" ]; then output "Something went wrong. No or wrong password given, aborting." $X; exit 1; fi # Clear Caches if [ $root ]; then sync; echo 4 > /proc/sys/vm/drop_caches; else $sudo sync; echo 4 | $sudo tee /proc/sys/vm/drop_caches > /dev/null; fi freemem_after=`cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2` && freemem_after=`echo "$freemem_after/1024.0" | bc` # Output Summary output "This freed `echo "$freemem_after - $freemem_before" | bc` MiB, so now you have $freemem_after MiB of free RAM." $X exit 0 -
pklaus revised this gist
May 12, 2011 . 1 changed file with 55 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,64 @@ #!/bin/bash ## Bash Script to clear cached memory on (Ubuntu) Linux ## By Philipp Klaus, rewritten by Stuck ## see <http://blog.philippklaus.de/2011/02/clear-cached-memory-on-ubuntu/> ## Minimum Requirements: ## - sudo (or being root) ## - stdin so running in terminal(-emulator) # Usage: output <"Message"> <$X> -- Output depends on running under X or in Command-Prompt function output { if [ $2 ]; then if [ "`which zenity`" ]; then zenity --info --text "$1" else if [ "`which xmessage`" ]; then xmessage "$1" else printf "$1" fi fi else printf "$1" fi } sudo=`which sudo` # Check Display - are we running X? If so use gksudo if [ $DISPLAY ]; then X=true; if [ "`which gksudo`" ]; then sudo=`which gksudo`; fi fi # Check user, script might already be run with sudo or as root if [ "`whoami`" == "root" ]; then root=true; fi # Is sudo installed? If not, abort unless running as root if [ ! "`which sudo`" ] && [ !$root ]; then output "Not Superuser, and sudo not found!" $X; exit 1; fi # If not running as root, gksudo not found but not running in terminal (like direct-command-line from Window-Manager), we have a problem: # we do not have stdin for sudo-password. # Try opening a terminal instead and notify user. if [ !$root ] && [ $X ] && [ ! "`which gksudo`" ] && [ ! -t 0 ] then output "Ouch! Not running in Terminal, gksudo not found and not running as superuser. Cannot ask for password! Trying to run in new terminal..." $X x-terminal-emulator -e $0& exit 1 fi # Get Memory Information freemem_before=`cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2` && freemem_before=`echo "$freemem_before/1024.0" | bc` cachedmem_before=`cat /proc/meminfo | grep "^Cached" | tr -s ' ' | cut -d ' ' -f2` && cachedmem_before=`echo "$cachedmem_before/1024.0" | bc` # Output Information output "This script will clear cached memory and free up your ram.\n\nAt the moment you have $cachedmem_before MiB cached and $freemem_before MiB free memory." $X # Clear Filesystem Buffer using "sync" if [ $root ]; then sync; else $sudo sync; fi # Did sync actually work? if [ "$?" != "0" ]; then output "Something went wrong. No or wrong password given, aborting." $X; exit 1; fi # Clear Caches echo "sync; echo 4 > /proc/sys/vm/drop_caches" | sudo su freemem_after=`cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2` && freemem_after=`echo "$freemem_after/1024.0" | bc` # Output Summary output "This freed `echo "$freemem_after - $freemem_before" | bc` MiB, so now you have $freemem_after MiB of free RAM." $X -
pklaus revised this gist
May 12, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ gksudo sync if [ "$?" != "0" ]; then echo "No or wrong password given, aborting."; exit 1 fi sudo sync; echo 4 | sudo tee /proc/sys/vm/drop_caches freemem_after=`cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2` && freemem_after=`echo "$freemem_after/1024.0" | bc` zenity --info --text "This freed `echo "$freemem_after - $freemem_before" | bc` MiB, so now you have $freemem_after MiB of free RAM." -
pklaus revised this gist
Feb 21, 2011 . 1 changed file with 8 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,18 +3,16 @@ ## Bash Script to clear cached memory on (Ubuntu) Linux ## see <http://blog.philippklaus.de/2011/02/clear-cached-memory-on-ubuntu/> freemem_before=`cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2` && freemem_before=`echo "$freemem_before/1024.0" | bc` cachedmem_before=`cat /proc/meminfo | grep "^Cached" | tr -s ' ' | cut -d ' ' -f2` && cachedmem_before=`echo "$cachedmem_before/1024.0" | bc` zenity --info --text "This script will clear cached memory and free up your ram.\n\nAt the moment you have $cachedmem_before MiB cached and $freemem_before MiB free memory." gksudo sync if [ "$?" != "0" ]; then echo "No or wrong password given, aborting."; exit 1 fi echo "sync; echo 4 > /proc/sys/vm/drop_caches" | sudo su freemem_after=`cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2` && freemem_after=`echo "$freemem_after/1024.0" | bc` zenity --info --text "This freed `echo "$freemem_after - $freemem_before" | bc` MiB, so now you have $freemem_after MiB of free RAM." -
pklaus created this gist
Feb 21, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/bin/sh ## Bash Script to clear cached memory on (Ubuntu) Linux ## see <http://blog.philippklaus.de/2011/02/clear-cached-memory-on-ubuntu/> freemem_before=`cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2` freemem_before=`echo "$freemem_before/1024.0" | bc` cachedmem_before=`cat /proc/meminfo | grep "^Cached" | tr -s ' ' | cut -d ' ' -f2` cachedmem_before=`echo "$cachedmem_before/1024.0" | bc` zenity --info --text "This script will clear cached memory and free up your ram.\n\nAt the moment you have $cachedmem_before MiB cached and $freemem_before MiB free memory." gksudo sync #echo "sync; echo 3 > /proc/sys/vm/drop_caches" | sudo su echo "echo 3 > /proc/sys/vm/drop_caches" | sudo su freemem_after=`cat /proc/meminfo | grep MemFree | tr -s ' ' | cut -d ' ' -f2` freemem_after=`echo "$freemem_after/1024.0" | bc` zenity --info --text "This freed `echo "$freemem_after - $freemem_before" | bc` MiB, so now you have $freemem_after MiB of free RAM."