# clear swapusage free_memory=`free -m | awk 'NR==2{print $7}'` used_swap=`free -m | awk 'NR==3{print $3}'` if [ $free_memory -gt $used_swap ]; then sudo swapoff -a && sudo swapon -a echo "Swap usage cleared!" else echo "Cannot clear swapusage, not enough memory!" fi2