1:curl(1查看http返回状态)
webStatus=`curl -I -s http://www.baidu.cc|grep 200|wc -l` [ $webStatus -eq 1 ] && echo "running" || echo "not running" //或者 httpHeader=`curl -s -I http://www.baidu.cc|sed -n '1p'|cut -d " " -f2` [ $httpHeader == 200 ] && echo "running" ||"not running"
2:curl(2查看命令执行是否成功)
curl -s http://www.baidu.com >&/dev/null [ $? -eq 0 ] && echo "running" ||echo "not running"
3:telnet
echo -e "\n"|telnet www.baidu.com 80|grep Connected|wc -l 返回1就表示已开启
4:nc
nc -w 5 .www.baidu.com 80 && echo "running" || "not running"
5:最后贴一个动态设置ip和端口的例子
[root@linhexiao shellTest]# cat check_web1.6.sh #!/bin/bash #create by linhexiao #V1.6 [ -f /etc/init.d/functions ] && . /etc/init.d/functions||exit 1 if [ $# -ne 2 ];then echo "Usage:$0 ip port" exit 1 fi httpPortNum=`nmap $1 -p $2|grep open|wc -l` if [ $httpPortNum == 1 ];then action "$1 $2 is running " /bin/true; else action "$1 $2 not running " /bin/false; fi