2014-02-06 101 views
0

如何通过linux shell检查某个url是否正在启动?我通过elinks试过,但它表明:如何通过linux shell检查url是否工作

错误:此应用程序需要在浏览器的JavaScript

+1

'curl -Is http://google.com | head -n 1' – MLeFevre

+0

我通常使用wget –

+1

这取决于你的意思是'working'。你的意思是如果服务器启动并响应内容?或者,如果内容本身有效? –

回答

3

您可以轻松地使用curl做到这一点(你可能必须安装卷曲,如果你的系统还没有它)。

例如,执行

curl -Is [URL YOU WANT TO CHECK] | head -n 1 

将返回一个http status code。然后,您可以通过此状态代码确定url是否存在。例如:

curl -Is http://stackoverflow.com/questions/21597851/how-to-check-whether-url-is-working-or-not-through-linux-shell | head -n 1 

即,您的问题,将返回200状态码。 HTTP/1.1 200 OK

但另一个网址,如

curl -Is http://stackoverflow.com/questions/madeupquestion/example | head -n 1 

将返回404,因为它不存在。 HTTP/1.1 404 Not Found