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 ...
- 11-10-2011 #1Just 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.
- 11-11-2011 #2Just Joined!
- Join Date
- Nov 2011
- Posts
- 5
Any hint on how to implement a timeout ??
Tks
- 11-11-2011 #3Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
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?
- 11-11-2011 #4Just 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.
- 11-11-2011 #5Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
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 hereLast edited by atreyu; 11-11-2011 at 03:20 PM. Reason: solution
- 11-11-2011 #6Just 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
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).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>
Do it clarify a little bit? Hope so
ps: Hmm, let me check the suggested alternative with netcat.. Thanks !!
- 11-11-2011 #7Just Joined!
- Join Date
- Nov 2011
- Posts
- 5
- 11-11-2011 #8


Reply With Quote
