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

相关文章
相关标签/搜索