Four, Shell Scripting combat fourth high-level programming

First, compare the size of two numbers

#!/bin/sh
read -p "Pls input two num:" a b
[ -z "$a" ] || [ -z "$b" ] && {
  echo "Pls input twn num agagin."
  exit 1
}
expr $a + 0 &>/dev/null
RETVAL1=$?
echo $RETVAL1
expr $b+0 &>/dev/null
RETVAL2=$?
echo $RETVAL2
test $RETVAL1 -eq 0 -a $RETVAL2 -eq 0 || {
        echo "Pls input two "num" ssagain."
        exit d2
}
[ $a -lt $b ] && {
        echo "$a < $b"
        exit 0
}
[ $a -gt $b ] && {
        echo "$a > $b"
        exit 0
}
[ $a -eq $b ] && {
        echo "$a = $b"
        exit 0
}
Second, the print menu
menu(){
 cat<<END
   1.[ install lamp ]
   2.[ install lnmp ]
   3.[ exit ]
   pls input the num you mant: 
END
}
menu
read -t 15 a
[ $a -eq 1 -o $a -eq 2 -o $a -eq 3 ]&&{
  echo " pls input right mum."
  exit
}
[ $a -eq 1 ]&&{
    echo "installing lamp"
    sleep 3
    echo "lamp is instlled"
   
    exit       
}
[ $a -eq 2 ]&&{
    echo "installing lnmp"
    sleep 3
    echo "lnmp is instlled"
    menu       
}
[ $a -eq 3 ]&&{
   exit
}
Third, the development of shell scripts to achieve if there is if3.sh / server / scripts below, if3.sh is output to the screen, if there is no script to create if3.sh
#!/bin/sh
path=/server/scripts
file=if3.sh
if [ ! -d $path ]
  then
    mkdir -p $path
    echo "$path is not exist,already create it"
be
if [ ! -f $path/$file ]
  then
    touch $path/$file
    echo "$path/$file is not exist,alreate create it"
    exit
fi
ls -l $path/$file
Fourth, the development of the script determining system remaining memory size, less than 100M, the alarm, the alarm after the test is successful, the system timing task execution added every 3 minutes a check
#!/bin/sh
used_men=`free -m|awk 'NR==3 {print $NF}'`
if [ $used_men -lt 800 ]
 then
   echo "men is not enough,$used_men"
   echo "men is nout enough,$used_men."|mail -s "men warning $(date +%F)" [email protected]
fi
  

 

 

 
 
 
              
 
 
 
 

Guess you like

Origin www.cnblogs.com/dangjingwei/p/11608243.html