#telnet放到子shell执行退出
[root@localhost ~]# (echo "quit") | telnet 127.0.0.1 22 #()放到子shell执行Trying 127.0.0.1... Connected to 127.0.0.1.Escape character is '^]'.Connection closed by foreign host.
#通过telnet监控22端口
[root@ryzc32 opt]# cat telnet.sh #!/bin/bashJG=`echo -e "\n" | telnet 192.168.1.30 22 | grep Connected | wc -l`if [ "$JG" == 1 ];then echo "0" #如果JG等于1,端口为通,输出0else echo "1" #如果JG等于0,端口不通,输出1fi
#通过nmap监控22端口
[root@localhost opt]# cat nmap.sh #!/bin/bashnamp=`nmap 192.168.100.50 -p 22 | grep open | wc -l`if [ "$namp" == 1 ];then echo 0else echo 1fi
#通过nc监控22端口
[root@localhost opt]# cat nc.sh #!/bin/bashnc -w 5 192.168.100.50 22 && echo 0 || echo 1
#通过wget判断
[root@mndg248 opt]# cat url_mon.sh #!/bin/bashwget -T 10 -c -q --spider www.baidu.com && RETVAL=$?if [ "$RETVAL" == 0 ];then echo "0"elsee cho "1"fi