Professional Documents
Culture Documents
/bin/sh
# Alexis Megas, 2015.
# Recycle swap if there is sufficient physical memory.
if [ ! $myid -eq 0 ]
then
echo "You must execute recycle_swap.sh as root. Aborting."
exit 1
fi
if [ ! -x "$free" ]
then
echo "Unable to locate free."
exit 1
fi
if [ ! -x "$swapoff" ]
then
echo "Unable to locate swapoff."
exit 1
fi
if [ ! -x "$swapon" ]
then
echo "Unable to locate swapon."
exit 1
fi
P=25
esac
done
if [ -z "$P" ]
then
echo "Incorrect percent value."
exit 1
fi
if [ -z "$freereal" ]
then
echo "awk and/or grep error(s)."
exit 1
fi
if [ -z "$usedswap" ]
then
echo "awk and/or grep error(s)."
exit 1
fi
if [ $usedswap -eq 0 ]
then
echo "Swap space is not consumed."
exit 0
fi
if [ $difference -le 0 ]
then
echo "Insufficient physical memory."
exit 1
fi
if [ -z "$totalreal" ]
then
echo "awk and/or grep error(s)."
exit 1
fi
if [ $totalreal -le 0 ]
then
echo "Unable to determine the total amount of physical memory."
exit 1
fi
if [ $P -lt $percent ]
then
echo "Insufficient physical memory: computed percentage is $percent, " \
"while P is $P."
exit 1
fi
swapoff="$swapoff -a"
$swapoff
if [ ! $? -eq 0 ]
then
echo "swapoff failure."
exit 1
fi
swapon="$swapon -a"
$swapon
if [ ! $? -eq 0 ]
then
echo "swapon failure."
exit 1
fi
exit 0