How do I determine if a web page exists with shell scripting?
来源:互联网 发布:软件维护招标文件 编辑:程序博客网 时间:2024/05/17 04:40
Under a *NIX, you can use curl to issue a simple HEAD request (HEAD only asks for the headers, not the page body):
curl --head http://myurl/
Then you can take only the first line, which contains the HTTP status code (200 OK, 404 Not Found, etc.):
curl -s --head http://myurl/ | head -n 1
And then check if you got a decent response (status code is 200 or 3**):
curl -s --head http://myurl/ | head -n 1 | grep "HTTP/1.[01] [23].."
This will output the first line if the status code is okay, or nothing if it isn't. You can also pipe that to /dev/null to get no output, and use $? to determine if it worked or no:
curl -s --head http://myurl/ | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null
# on success (page exists), $? will be 0; on failure (page does not exist or
# is unreachable), $? will be 1
EDIT -s simply tells curl to not show a "progress bar".
- How do I determine if a web page exists with shell scripting?
- In a combobox, how do I determine the highlighted item (not selected item)?
- How do I determine the expiration date of a p12 certificate?
- How do I create a time-series object with dates?
- How do I tell if a regular file does not exist in bash?
- [lua] How do I know if a table is an array?
- How do I install a file in my local repository along with a generic POM?
- How do I read in a character variable with varying length in a space delimited dataset?
- How do I read in a character variable with varying length in a space delimited dataset?
- how do i rotate a matrix transformation with a centered origin
- How Do I get Started with Oracle?
- How do I get started with CUDA?
- How to determine if a machine is localhost?
- How do I filtered TextBox with a Decimal (double) Data Type
- How do I generate compatible train and test sets that get processed with a filter?
- How do I reset a jquery-chosen select option with jQuery?重置chosen组件值状态
- Magento shows blank/empty page. How do I solve this?
- Magento shows blank/empty page. How do I solve this?
- Android - 资源的定义和引用
- 简单的数据库摘要
- java 调用存储过程
- 【图像处理】Haar Adaboost 检测自定义目标(视频车辆检测算法代码)
- JXL解析Excel
- How do I determine if a web page exists with shell scripting?
- Perl 访问FTP
- POJ 1862 Stripies 贪心+优先队列
- 【玩转微信公众平台之二】 账号注册
- JTable用法
- jquery提交json数据到mvc4服务端
- Start and Stop Oracle Weblogic NodeManager Via Shell Alias
- 设计模式系列课程11之【抽象工厂模式】
- C++中sizeof的用法