例子: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