我试图从wget的结果中提取一条线但是遇到了麻烦.这是我的wget电话:
$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html
输出:
--18:24:12-- http://xxx.xxxx.xxxx:15000/myhtml.html => `-' Resolving xxx.xxxx.xxxx... xxx.xxxx.xxxx Connecting to xxx.xxxx.xxxx|xxx.xxxx.xxxx|:15000... connected. HTTP request sent, awaiting response... HTTP/1.1 302 Found Date: Tue, 18 Nov 2008 23:24:12 GMT Server: IBM_HTTP_Server Expires: Thu, 01 Dec 1994 16:00:00 GMT Location: https://xxx.xxxx.xxxx/siteminderagent/... Content-Length: 508 Keep-Alive: timeout=10, max=100 Connection: Keep-Alive Content-Type: text/html; charset=iso-8859-1 Location: https://xxx.xxxx.xxxx//siteminderagent/... --18:24:13-- https://xxx.xxxx.xxxx/siteminderagent/... => `-' Resolving xxx.xxxx.xxxx... failed: Name or service not known.
如果我这样做:
$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html | egrep -i "302"
它不会返回包含字符串的行.我只想检查网站或siteminder是否已启动.
你正在寻找的wget的输出写在stderr上.你必须重定向它:
$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html 2>&1 | egrep -i "302"
wget
将标题打印到stderr,而不是标准输出.您可以将stderr重定向到stdout,如下所示:
wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html 2>&1 | egrep -i "302"
"2>&1"部分表示将文件描述符2(stderr)重定向('>')到文件描述符1(stdout).