netcatの応答をテキストファイルに書き込む

netcatの応答をテキストファイルに書き込む

リモート サーバーに SOAP 要求を送信し、ターミナルで応答を返すスクリプト ファイルがあります。ただし、後で使用するために、この応答をターミナルからテキスト ファイルに保存する必要があります。

次のような netcat リクエストがあります:

#!/bin/sh

HOST=192.168.2.220
PORT=8080

nc  $HOST $PORT 0 << __EOF__
POST / HTTP/1.1
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
 <SOAP-ENV:Header/>
 <SOAP-ENV:Body>
  <adm:serverInfo xmlns:adm="http://log4ensics.com/2010/AdminInterface"/>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
__EOF__ 

ターミナルに次のような応答があります

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fb="http://log4ensics.com/2010/AdminInterface/FileBinding" xmlns:mb="http://log4ensics.com/2010/AdminInterface/ModuleBinding" xmlns:rb="http://log4ensics.com/2010/AdminInterface/RouteBinding" xmlns:sb="http://log4ensics.com/2010/AdminInterface/ServerBinding" xmlns:ns="http://log4ensics.com/2010/AdminInterface"><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body><ns:serverInfoReply><started>1444714509692781</started><load>0.126918644</load><pid>948</pid><mem>14745600</mem><modules><module-name>eventlog</module-name><evt-recvd>249668</evt-recvd><evt-drop>0</evt-drop><evt-fwd>249668</evt-fwd><queuesize>0</queuesize><status>3</status><module-type>1</module-type><module>im_msvistalog</module></modules><modules><module-name>agentlogging</module-name><evt-recvd>1</evt-recvd><evt-drop>0</evt-drop><evt-fwd>1</evt-fwd><queuesize>0</queuesize><status>2</status><module-type>1</module-type><module>im_internal</module></modules><modules><module-name>logcontents</module-name><evt-recvd>249668</evt-recvd><evt-drop>0</evt-drop><evt-fwd>249668</evt-fwd><queuesize>0</queuesize><status>3</status><module-type>3</module-type><module>om_tcp</module></modules><modules><module-name>agentlog</module-name><evt-recvd>0</evt-recvd><evt-drop>0</evt-drop><evt-fwd>0</evt-fwd><queuesize>157</queuesize><status>1</status><module-type>3</module-type><module>om_tcp</module></modules><version>2.9.1427</version><os>Windows</os><systeminfo>Windows Server 2012, 2 CPU(s), 4.0Gb memory</systeminfo><hostname>ADServer</hostname><servertime>1444716606837528</servertime></ns:serverInfoReply></SOAP-ENV:Body></SOAP-ENV:Envelope>

この応答をテキスト ファイルに書き込むにはどうすればよいですか。???

答え1

見る出力をファイルにリダイレクトする:

#!/bin/sh

HOST=192.168.2.220
PORT=8080

nc  $HOST $PORT 0 << __EOF__ > output.txt
POST / HTTP/1.1
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
 <SOAP-ENV:Header/>
 <SOAP-ENV:Body>
  <adm:serverInfo xmlns:adm="http://log4ensics.com/2010/AdminInterface"/>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
__EOF__ 

関連情報