尝试创建一个脚本,检查是否使用cat / proc / meminfo挂载交换,如果输出大于0,则记录消息:交换已挂载,如果不执行命令:swapon / swap
#!/bin/sh if cat /proc/meminfo | grep SwapTotal | awk '{print $2}' = 0 then swapon /swap else echo Swap already mounted fi
答案 0 :(得分:1)
尝试此命令 -
awk '/SwapTotal/ {if($2==0) {system("swapon /swap")} else print "Swap already mounted"}' /proc/meminfo
答案 1 :(得分:0)
尝试:
if [[ -z $(awk '/SwapTotal/{print $2}' /proc/meminfo) ]]
then
swapon /swap
else
echo Swap already mounted
fi