Find the answer to your Linux question:
Results 1 to 8 of 8
Hi all My intention is to perform a telnet command with a timeout feature. I'm trying to implement it through a shell script which: 1. Starts a counter 2. Issue ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2011
    Posts
    5

    Command timeout with Shell Script


    Hi all

    My intention is to perform a telnet command with a timeout feature.
    I'm trying to implement it through a shell script which:
    1. Starts a counter
    2. Issue the telnet command (in background)
    3. Checks if the timeout was reached or the telnet command finished (while loop)
    4. If timeout was reached, kills the telnet command
    5. If the command executed well, stops the counter
    6. Calculates the time difference

    I started scripting, but faced a problem with the return code from the telnet command.

    The code: pastebin . com / HumprZUD

    Thanks guys.

  2. #2
    Just Joined!
    Join Date
    Nov 2011
    Posts
    5
    Any hint on how to implement a timeout ??

    Tks

  3. #3
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Let me get it straight: so you want to run a telnet job in the background, and after some specified internal, kill the telnet job, if still running?

  4. #4
    Just Joined!
    Join Date
    Nov 2011
    Posts
    5
    Exactly, but I need to get the result from the telnet. If the server refused the connection or not.

  5. #5
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Why do you need to run it in the background, though? Can you give examples of what might normally be returned by your telnet command?

    Are you just testing if telnet is running? Is is that you are testing that the ip might be down, or that the port is closed, or that the service is down? or something else?

    You can verify that the port is open with:
    nmap -n -p 23 <TELNET_SERVER_IP>

    Edit: maybe a solution for you is here
    Last edited by atreyu; 11-11-2011 at 03:20 PM. Reason: solution

  6. #6
    Just Joined!
    Join Date
    Nov 2011
    Posts
    5
    Let me put some context here
    The intention behind all of this is to get the IP/Port latency.

    I expect the line "Escape character is '^]'.", like below:

    telemoni@scotipandora001:/tmp> telnet 10.27.32.34 1828
    telemoni@scotipandora001:/tmp> telnet 10.27.32.34 1828
    Trying 10.27.32.34...
    Connected to 10.27.32.34.
    Escape character is '^]'.
    Connection closed by foreign host.
    telemoni@scotipandora001:/tmp>
    I'm running it in background in order to don't get stucked on the telnet and to run the timer to check the timeout (in some cases the telnet delays a LOT).

    Do it clarify a little bit? Hope so

    ps: Hmm, let me check the suggested alternative with netcat.. Thanks !!

  7. #7
    Just Joined!
    Join Date
    Nov 2011
    Posts
    5

    Solved

    Nmap is the easiest way to go
    I forgot nmap's output includes the latency...

    Code:
    nmap --host-timeout 15000 10.27.32.34 -p 1830 | awk {'print $11'} | tail -1
    Thanks atreyu


    Quote Originally Posted by atreyu View Post
    Why do you need to run it in the background, though? Can you give examples of what might normally be returned by your telnet command?

    Are you just testing if telnet is running? Is is that you are testing that the ip might be down, or that the port is closed, or that the service is down? or something else?

    You can verify that the port is open with:
    nmap -n -p 23 <TELNET_SERVER_IP>

  8. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by robas View Post
    I forgot nmap's output includes the latency...
    me too! np

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •