I want to check whether Swap space exist on a centos box in my bash script.Thus in cash there are no swap space on the server , then i can create swap.
I tried this approach
if [[ -n $(swapon -s) ]]; then
:
else
mkswap /dev/vda2 &> /dev/null
swapon /dev/vda2
fi
Obviously it won't work since even when there is no swap swapon -s
will return a string
Filename Type Size Used Priority