Topic
2 replies Latest Post - ‏2012-05-02T21:43:47Z by SeanWalberg
SystemAdmin
SystemAdmin
232 Posts
ACCEPTED ANSWER

Pinned topic facing issues in telnet using script

‏2012-04-25T08:58:42Z |
i have tried to run this script and capturing the output in a file

#!/bin/sh
telnet 10.161.240.2 8100 << EOF
<?xml version="1.0"?> <login_command><sequence id="1" /> <access id="1"/> <user name = "ttmlcnms" password = "cnms#123"/> </login_command>
<?xml version="1.0"?> <RegistrationDescriptor><sequence id="1" /> <access id="1"/> <attributeDescriptors><action>Register</action> </attributeDescriptors> </RegistrationDescriptor>
EOF

but
error is coming as "Connection Closed by Foreign Host"
pls help me
Updated on 2012-05-02T21:43:47Z at 2012-05-02T21:43:47Z by SeanWalberg
  • romeo_ninov
    romeo_ninov
    3 Posts
    ACCEPTED ANSWER

    Re: facing issues in telnet using script

    ‏2012-04-26T07:07:58Z  in response to SystemAdmin
    Check if on 10.161.240.2 is run iptables
    to capture the output try this format

    command>output <<EOD
    1
    2
    3
    EOD
  • SeanWalberg
    SeanWalberg
    1 Post
    ACCEPTED ANSWER

    Re: facing issues in telnet using script

    ‏2012-05-02T21:43:47Z  in response to SystemAdmin
    You're sending the data to the remote server, but you're not waiting for the answer! If you redirect STDIN, the pipe is closed once you run out of input.

    $ telnet ertw.com 80 << EOF
    > GET / HTTP/1.1
    > Host: ertw.com
    >
    > EOF
    Trying 72.14.178.137...
    Connected to ertw.com.
    Escape character is '^]'.
    Connection closed by foreign host.

    If you sleep, you should get the answer:

    $ (echo "GET / HTTP/1.1"; echo "Host: ertw.com"; echo; sleep 5) | telnet ertw.com 80
    Trying 72.14.178.137...
    Connected to ertw.com.
    Escape character is '^]'.
    HTTP/1.1 200 OK
    Server: nginx/0.8.55
    Date: Wed, 02 May 2012 21:44:09 GMT
    Content-Type: text/html
    Transfer-Encoding: chunked
    Connection: keep-alive
    X-Powered-By: PHP/5.3.3

    ...