Reputation: 3
Trying to create a script which is checking if swap is mounted with cat /proc/meminfo, if output is greather than 0, log a message: Swap already mounted, if not execute a command: swapon /swap
#!/bin/sh if cat /proc/meminfo | grep SwapTotal | awk '{print $2}' = 0 then swapon /swap else echo Swap already mounted fi
Upvotes: 0
Views: 91
Reputation: 133538
try:
if [[ -z $(awk '/SwapTotal/{print $2}' /proc/meminfo) ]]
then
swapon /swap
else
echo Swap already mounted
fi
Upvotes: 0
Reputation: 3147
try this command -
awk '/SwapTotal/ {if($2==0) {system("swapon /swap")} else print "Swap already mounted"}' /proc/meminfo
Upvotes: 1