if 判斷練習

例子:ide

#!/bin/sh3d

a=$1server

b=$2blog

if [ $a -gt $b ]ip

then內存

  echo "yes,$a >= $b"get

fiit


if [ $a -le $b ]io

  thenclass

  echo "yes,$a <= $b"

fi



判斷/server/scripts目錄下if3.sh文件是否存在,不存在則建立:

#!/bin/sh

FILEPATH="/server/scripts"

if [ -e "$FILEPATH/if3.sh" ]

then

  echo "$FILEPATH/if3.sh exist."

fi

if [ ! -e "$FILEPATH/if3.sh" ]

then 

  [ ! -d $FILEPATH ] && mkdir -p $FILEPATH

  [ -d $FILEPATH ] && {

 cd $FILEPATH

 touch if3.sh

 echo "if3.sh is touch."

}

fi


判斷系統內存是否小於100M,小於100M則發郵件報警:

#!/bin/sh

cur_free=`free -m|awk '/buffers\// {print $NF}'`

if [ $cur_free -lt 100 ];

then 

echo "current memory is $cur_free."|mai -s "current memory is $cur_free." 23124@qq.com

fi


wKioL1mEtI7iV7RgAADPzCccPsw346.pngwKioL1mEtJGgqcPhAADrXIJ2kBg065.png

wKiom1mEtJLS5H_IAAB90JNTG5A349.png

wKioL1mEtJPj8fH3AACsPsIBiuI604.png

wKiom1mEtJXS7ChuAAFJRF2bXmc378.png

wKiom1mEtX_ypN30AADOM_8vYgo611.png

相關文章
相關標籤/搜索