- 参考地址http://jeekchen.iteye.com/blog/976819
- #!/bin/bash
- cd /usr/vm/server/tomcat6/webapps/mytv365/sitemap/baiduVideo
- ##取出http://xxxxx.html这种URL
- file=`cat sitemap_new.xml | grep "http://.*html" | awk -F"[" '{print $3}' | awk -F"]" '{print $1}' >/opt/file`
- for i in `cat $file`
- do
- ###这句是核心
- http_code=`curl -o /dev/null -s -w "%{http_code}" $i`
- ###如果状态是404则输出url 状态码到文件中
- if [ $http_code = 400 ]
- then
- echo "$i" "$http_code" >>/home/httpcheck
- fi
- done
- ps:运行下面语句得到类似结果
- [root@nagios ~]# curl -o /dev/null -s -w "%{http_code}" http://www.baidu.com
- 200
转载于:https://blog.51cto.com/liveforlinux/917134