Advertisement
marcoshalano

Simple and verborragic script to clean memory cache

Aug 23rd, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.74 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # I heavly adapted this script from http://www.vivaolinux.com.br/script/limpa-cache11sh
  4. # I think the original code is ugly and slow, but has some usable lines.
  5. # Instructions: Put this script on your path or create a alias for them, so you can use easily.
  6.  
  7.  
  8. echo "Total memory in the system: $(sudo dmidecode -t 19 | grep Range|awk '{print $3 " " $4}')"
  9. MEM1=$(free|awk '/Mem:/ {print int(100*$3/$2)}')
  10. echo "RAM memory occupied before cleaning: $MEM1%"
  11. echo "Cleaning RAM..."
  12. sync
  13. echo 3 | sudo tee /proc/sys/vm/drop_caches >/dev/null
  14. echo "Cleaning swap..."
  15. sudo swapoff -a
  16. sudo swapon -a
  17. MEM2=`free|awk '/Mem:/ {print int(100*$3/$2)}'`
  18. echo "Memory occupied after cleaning: $MEM2%"
  19. echo "Economy: $(expr $MEM1 - $MEM2)%"
  20.  
  21. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement