將 netcat 的回應寫入文字文件

將 netcat 的回應寫入文字文件

我有一個腳本文件,它將肥皂請求發送到遠端伺服器,並在終端中給出回應。不過,我希望從終端向文字檔案做出此回應,以便稍後使用它。

我有一個 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__ 

相關內容