1: curl (1 to view the http return status)
webStatus=`curl -I -s http://www.baidu.cc|grep 200|wc -l` [ $webStatus -eq 1 ] && echo "running" || echo "not running" //or httpHeader=`curl -s -I http://www.baidu.cc|sed -n '1p'|cut -d " " -f2` [ $httpHeader == 200 ] && echo "running" ||"not running"
2: curl (2 to see if the command was executed successfully)
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 Returning 1 means it is enabled
4:nc
nc -w 5 .www.baidu.com 80 && echo "running" || "not running"
5: Finally, paste an example of dynamically setting ip and port
[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 be 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; be