From af0962c2785e9cbdbd87724df244e674fef6e352 Mon Sep 17 00:00:00 2001 From: xiaoz Date: Tue, 22 Dec 2020 16:25:12 +0800 Subject: [PATCH] fix bug --- set_swap.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/set_swap.sh b/set_swap.sh index be67337..a19f027 100644 --- a/set_swap.sh +++ b/set_swap.sh @@ -5,8 +5,10 @@ #获取物理内存 p_mem=`free -m|grep Mem|awk '{print $2}'` -#获取最佳虚拟内存大小 +#获取虚拟内存大小 +get_swap=`free -mt|grep 'Swap'|awk '{print $2}'` +#获取最佳虚拟内存大小 #内存如果小于2g,则设置2倍 if [ $p_mem -lt 2000 ] then @@ -32,12 +34,8 @@ function set_swap(){ } #判断当前是否开启了虚拟内存 -if swapon -s +if [ $get_swap == 0 ] then - echo '---------------------------------' - echo 'You have already set up swap, there is no need to repeat the settings.' - exit -else #设置虚拟内存 set_swap echo '---------------------------------' @@ -47,6 +45,9 @@ else echo '---------------------------------' free -mt echo '---------------------------------' +else + echo '---------------------------------' + echo 'You have already set up swap, there is no need to repeat the settings.' fi exit \ No newline at end of file