判断内存小于100,邮件报警
[root@shnne ~]# sh baojing.sh the mem is 570,it's ok. [root@shnne ~]# vim baojing.sh #!/bin/sh memvalue=`free -m|awk 'NR==3 {print $NF}'` if [ $memvalue -gt 100 ] then echo "the mem is $memvalue,it's ok." else echo "the mem is $memvalue,less than 100."|mail -s "mem waring" 1138269007@qq.com fi
2.判断两个数的大小
[root@shnne ~]# cat if1.sh #!/bin/sh #read -p "please input two number:" a b a=$1 b=$2 [ -z $a ] || [ -z $b ] && { echo "USAGE:num1 num2" exit } expr $a + 0 >/dev/null 2>&1 RETVAL1=$? expr $b + 0 >/dev/null 2>&1 RETVAL2=$? if [ $RETVAL1 -ne 0 ] || [ $RETVAL2 -ne 0 ] then echo "please input number" exit fi if [ $a -lt $b ] then echo "$a < $b" elif [ $a -eq $b ] then echo "$a = $b" else echo "$a > $b" fi exit
3.菜单打印
[root@shnne ~]# cat menu.sh #!/bin/sh #echo "*********************************" #echo "* Please choice the menu list *" #echo "* 1.print the hostname *" #echo "* 2.exit *" #echo "*********************************" menu() { cat <4.限定read后输入的个数
[root@shnne ~]# vim read.sh #!/bin/sh read -p "pls input two num:" a b c if [ -n "$c" ] then echo "pls input two nmu" exit 2 fi