質問

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" <br/>

文字列を含む行は返されません。サイトまたはサイトマインダーが起動しているかどうかを確認したいだけです。

役に立ちましたか?

解決

探しているwgetの出力はstderrに書き込まれます。リダイレクトする必要があります:

$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html 2>&1 | egrep -i "302" 

他のヒント

wget は、ヘッダーを標準出力ではなく標準エラー出力に出力します。次のように、stderrをstdoutにリダイレクトできます。

wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html 2>&1 | egrep -i "302"

&quot; 2&gt;&amp; 1&quot;一部は、ファイル記述子2(stderr)をファイル記述子1(stdout)にリダイレクト( '&gt;')するよう指示しています。

既に提供されているソリューションの少し強化されたバージョン

  

wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml。 html 2&gt;&amp; 1&gt; / dev / null | grep -c 302

2&gt;&amp; 1&gt; / dev / null は、不要な出力を削除します。この方法では、egrepはwgetのstderrのみを解析し、302を含む文字列をstdoutからキャッチする可能性を排除します(htmlファイル自体が出力され、結果のバイト数がe.t.cのダウンロードプロセスバー):)

egrep -c は、単に出力するのではなく、一致した文字列の数をカウントします。 egrepが一致した文字列の量を知るには十分です。

wget --server-response http://www.amazon.de/xyz 2&gt;&amp ; 1 | awk '/ ^ HTTP / {print $ 2}'

ちょっと説明します。元の質問の -S スイッチは、-server-response の省略形です。

また、OPが wget を指定していることは知っていますが、 curl は似ており、デフォルトはSTDOUTです。

curl --head --silent $yourURL

または

curl -I -s $yourURL

-silent スイッチは、 grep -abilityにのみ必要です:( -s は進捗%メーターをオフにします)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top