if 判断练习

前端之家收集整理的这篇文章主要介绍了if 判断练习前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

例子:

#!/bin/sh

a=$1

b=$2

if [ $a -gt $b ]

then

echo "yes,$a >= $b"

fi


if [ $a -le $b ]

then

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.png

wKioL1mEtJGgqcPhAADrXIJ2kBg065.png

wKiom1mEtJLS5H_IAAB90JNTG5A349.png

wKioL1mEtJPj8fH3AACsPsIBiuI604.png

wKiom1mEtJXS7ChuAAFJRF2bXmc378.png

wKiom1mEtX_ypN30AADOM_8vYgo611.png

原文链接:https://www.f2er.com/bash/391614.html

猜你在找的Bash相关文章