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__ 

관련 정보