Auto-exit from telnet prompt


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Auto-exit from telnet prompt
# 1  
Old 03-23-2011
Auto-exit from telnet prompt

Hi,
Hope all your are doing well. Need a suggestion from you.
I am writing an automated shell script that will effectively check the telnet connectivity with different backends from present deployment server.

Ideally, this script reads each backend hostname from a configuration file and fires telnet command on that. like
Code:
telnet $hostname $port

but the catch here is, if the connection is established shell holds the prompts there, it does not automatically exits. I get something like

Code:
telnet  hostname 443
Trying **.***.***.*...
Connected to **.**.**.**
Escape character is '^]'.

Sometime if the remote host does not respond then it holds for long time,
Code:
telnet  hostname 443
Trying **.***.***.*...

This symbolises we need manual intervention clearly to come out. I want script should wait for certain interval if it does not get response come out and try next host.

Any ideas how to implement?
I can not use expect technogloy as it is not permitted in our environment.
I tried google and search in this forum as well, but did find a suitable approach.

Please let me know your ideas, any help would be very much appreciated.

Thanks in anticipation.
Regards,
Bhaskar
# 2  
Old 03-23-2011
Making it quit once it connects at least might be more doable. Redirect standard input from /dev/null. It will try to read from stdin once it connects, get EOF, and quit normally.

telnet doesn't seem to have any timeout options. It's a pain in general to automate. You'll have to kill it externally.

Code:
telnet hostname port < /dev/null > /dev/null &
PID=$!

sleep 3
# Can't kill something that's dead, so if telnet's finished already
# killing it won't change its exit status from zero to nonzero.
kill "$PID"
if ! wait
then
        echo "No telnet"
fi

Is netcat (nc) available? It has timeouts and such, and doesn't depend on terminals, so is much less torturous to automate.
# 3  
Old 03-23-2011
Hi Corona,

It was indeed a great experience to run your snippet.

I varied the waiting time and launched the process in background was indeed a good idea. May be I tried reading from config file rather than /dev/null it also worked.

Thanks a lot for this idea!!

I think nc is available in our env and it can be used as a substitute of telnet command. I will suggest these to team members.

Once again Thanks a lot.
Have great time.

Cheers!!
Bhaskar
# 4  
Old 03-23-2011
Quote:
Originally Posted by bhaskar_m
May be I tried reading from config file rather than /dev/null it also worked.
??? That's stuff that'd be fed raw into telnet! Make it an empty file Smilie
# 5  
Old 03-24-2011
Slightly off topic. Port 443 is not normally used for telnet.
If you are trying to write some sort of port scanner be very careful. It is possible to crash a system by firing whatever ports are live in "inetd". I have also seen systems block all incoming TCP/IP connections when under attack thus causing a "denial of service" situation.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Auto enter for prompt messages

Hello everybody, I am coding a script, that allow the user to enter some information using prompt messages, i.e: sEpisode=1 read -e -i "$sEpisode" -p "Start download from episode: " downloadFrom sEpisode="${downloadFrom:-$sEpisode}" This code allows the user to set the download from... (4 Replies)
Discussion started by: Abu Rayane
4 Replies

2. Solaris

Zone console login prompt exit

Hi , I am not able to exit fom zone console login prompt. I have tried options like ~. ~~. and @. but it is not working fo me. Could someone Please help me on this. Thanks in Advance!! Regards, Laxxi (7 Replies)
Discussion started by: Laxxi
7 Replies

3. Shell Programming and Scripting

How to exit prompt when starting a weblogic administration server remotely?

Hi, I am trying to start Weblogic Admin server using start-up script (./startWeblogic.sh) from a remote host using a different user. The server starts fine but prompt is stuck, it does not return Background: We have multiple admin servers in different environment and the requirement is all... (4 Replies)
Discussion started by: bhaskar_m
4 Replies

4. Shell Programming and Scripting

how do I infinite loop (reconnect) to auto disconnect telnet server

I want the text based Star Wars movie at towel.blinkenlights.nl to loop infinitely. It plays the movie and then disconnects my session? Can anyone think of a way to make my unix machine automatically reconnect over and over? EDIT no commands are required are the connection its just in and... (3 Replies)
Discussion started by: herot
3 Replies

5. Shell Programming and Scripting

Exit from Shell Prompt after Pbrun

I have a ksh script, which pbruns into another account. I want to pbrun run into that account, and continue running all the engine commands(i.e setroot, setsite xxx, etc) in my script. But instead, it pbruns into the account, and just gives me a shell prompt.. and stops there. Only once i... (2 Replies)
Discussion started by: alamurus
2 Replies

6. Shell Programming and Scripting

Net::Telnet (match prompt)

Hi, The code below is used to telnet to list of devices and configure them. The program executes in this manner: 1. telnet to the first device in file.txt 2. one the telnet command is executed a "press any key to continue" prompts. 3. once a return key is executed it ask for username,... (1 Reply)
Discussion started by: sureshcisco
1 Replies

7. Shell Programming and Scripting

Telnet in command prompt

Hi, i have typed telnet yahoo.com 80 in command prompt it displays as a blank command prompt page titling as Telnet Yahoo.com Other than that i am not able to get anything. can anyone sort me out the reason for this (12 Replies)
Discussion started by: satheeshkr_cse
12 Replies

8. Shell Programming and Scripting

KSH: Test telnet and exit

Hi, I need to do a test Telnet in KSH and if the connection is good then disconnect the telnet session with out logging in and without exiting the shell script. Example output of a good connection: $telnet xxx.xx.xx.xxx xxxx Trying xxx.xx.xx.xxx... Connected to xxx.xx.xx.xxx. Escape... (1 Reply)
Discussion started by: calex
1 Replies

9. Shell Programming and Scripting

How to get the exit satus of a command which I executed in sftp prompt

Hi All, I need the exit status of a command which is executed through sftp connection. Example: sftp user@host <<EOF mkdir /home/karteek/testing put /home/xyz.txt /home/karteek/testing EOF ------ In the above example, I need the exit status of the put command. Please help me. ... (2 Replies)
Discussion started by: Karteek
2 Replies

10. UNIX for Dummies Questions & Answers

Exit from telnet when run Remotely

ssh user@host -q -n 'grep `hostname` /etc/hosts; telnet 10.100.23.45 1234;' When i run this command remotely it is hanging and not giving me the prompt, Can anyone tell me how can I exit a telnet command remotely please. Thanks. (10 Replies)
Discussion started by: venu_nbk
10 Replies
Login or Register to Ask a Question