Public domain
#!/bin/sh
free -m
echo
sync
echo 3 > /proc/sys/vm/drop_caches
echo 0 > /proc/sys/vm/drop_caches
FREE_RAM=$(free|grep Mem:|awk '{print $4}')
SWAP_SIZE=$(free|grep Swap:|awk '{print $3}')
echo "Free RAM  : ${FREE_RAM}"
echo "Used SWAP : ${SWAP_SIZE}"
if [ "${FREE_RAM}" -gt "${SWAP_SIZE}" ]; then
  swapoff -a
  swapon -a
  echo
  free -m
else
  echo "Not enough Free RAM"
fi
echo
BY: Pejman Moghadam 
TAG: swap, bash-script, bash 
DATE: 2009-10-22 13:50:56