将 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__ 

相关内容