SHELL SCRIPT 无聊小程序(二)

eg1、根据用户的不同选择,程序显示不同的结果。Y就显示“OK, continue " N显示"Oh , interrupt!" 

           如果不是Y/y/N/n之内的其他字符,就显示“I don't know what your choice is."

           #!/bin/bash

           #Program:

           #                This program shows the user's choice

           #History:

           #2011/12/15 Jason First release

           PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin/:~/bin
           export PATH

            read -p "Please input  your choice:"     yn

            if [ $yn = Y ]  || [ $yn = y ]; then

            echo "OK , continue "

            exit 0

           elif [ $yn = N ] || [ $yn = n ] ; then

             echo "Oh , interrupt ."

            else 

            echo  "  I don't know what your choice is."

          fi

 

 

eg2、判断$1是否为hello ,如果是的话就显示"Hello  , hou are you. "; 如果没有加任何参数,就提示用户必须使用参数 ;  如果参数不是hello ,提示只能输入hello


#!/bin/bash
#Program:
#       Check $1 is equal to "hello"
#History:
#2011/12/15 Jason First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin/:~/bin
export PATH
if [ "$1" == "hello" ] ; then
echo "Hello , how are you?"
exit 0
elif [ "$1" == "" ] ; then
echo "You must input a parameter!"
exit 0
else
echo "You just can input hello!"
exit 0
fi
#!/bin/bash
#Program:
#       Check $1 is equal to "hello"
#History:
#2011/12/15 Jason First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin/:~/bin
export PATH
if [ "$1" == "hello" ] ; then
echo "Hello , how are you?"
exit 0
elif [ "$1" == "" ] ; then
echo "You must input a parameter!"
exit 0
else
echo "You just can input hello!"
exit 0
fi
                      #!/bin/bash
                      #Program:
                      #       Check $1 is equal to "hello"
                      #History:
                      #2011/12/15 Jason First release
                      PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin/:~/bin
                      export PATH
                      if [ "$1" == "hello" ] ; then
                      echo "Hello , how are you?"
                      exit 0
                      elif [ "$1" == "" ] ; then
                      echo "You must input a parameter!"
                      exit 0
                      else
                      echo "You just can input hello!"
                      exit 0
                      fi

 

eg3、检查服务器上,www/ssh/ftp/mail服务是否开启

 

                  #!/bin/bash
                  #Program:
                  #      This program test "www" server "ssh" server "ftp" server and "mail" server already open.
                  #History:
                  #2011/12/15  Jason Frist release
                  PATH=/bin:/sbin:/usr/bin:/usr/sbin/:/usr/local/bin:/usr/local/sbin/:~/bin
                  export PATH
                  echo "Now , I will detect Linux server's services!"
                  echo "The www , ftp , ssh and  mail will be detected!"
                  testing=$(netstat -tuln | grep ':80 ')
                  if [  -n "$testing" ] ; then
                  echo "Your www service is open."
                  else
                  echo "Your www service is closed."
                  fi
                  testing=$(netstat -tuln | grep ':22 ')
                  if [  -n "$testing" ] ; then
                  echo "Your ssh service is open."
                  else
                  echo "Your ssh service is closed."
                  fi
                  testing=$(netstat -tuln | grep ':21 ')
                  if [  -n "$testing" ] ; then
                 echo "Your ftp service is open."
                 else
                 echo "Your ftp service is closed."
                 fi
                 testing=$(netstat -tuln | grep ':25 ')
                 if [  -n "$testing" ] ; then
                 echo "Your mail service is open."
                 else
                 echo "Your mail service is closed."
                 fi

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值