Telnet from shell script , further need to logout if log in not authenticate


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Telnet from shell script , further need to logout if log in not authenticate
# 1  
Old 05-31-2011
Telnet from shell script , further need to logout if log in not authenticate

Using unix shell script file I need to telnet to a IP further send a command to the telnet IP and get the response to a file with out using "expect" utility and I have achieved this by below command.

Code:
(sleep 3; echo admin; sleep 3; echo mypass; sleep 5;echo "show status-list"; sleep 5; echo "logout")|telnet 192.168.1.1 >>$telnet_result

But now if the user "name" or "password" is wrong we get "Failed login" when we try to telnet. I need to catch this for the first attempt itself and exit the telnet session immediately.

Code:
(sleep 3; echo admin; sleep 3; echo mypass; ... )|telnet 192.168.1.1 | grep "Failed" | " Need To Write Code here I guess To Exit if FAILED" | >>$telnet_result

Smilie

Or else is their any other way or method so that I can get the "Failed Login" and exit the telenet session?. Please suggest.

Thanks
Raghunath Rao
# 2  
Old 05-31-2011
The "with out using "expect" utility " stipulation makes this sound like homework. However try the following (though I suspect your lecturer will have mentioned it already)
Code:
man nc

# 3  
Old 06-01-2011
Not able to achieve... any one any updates/suggestion on this.
If any other approach to telnet from shell script with out using "expect" will be of great help please suggest.
Cheers
Raghu
# 4  
Old 06-01-2011
This is homework. The same question was asked in the homework section, which would be the correct place for this post.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need shell script for SMS via telnet command

I am not very much familiar with telnet based scripting so I would need your help to directly submitting sms as deliver_sm or submit_sm msg to SMSC (IP & system_id and password are already known). So, need your help to provide such script. I previously used such script but my harddisk crashed and... (1 Reply)
Discussion started by: wasay
1 Replies

2. Shell Programming and Scripting

Using telnet in my shell script

Hello Guys, I have a linux server where I already logged in, once logged in, i telnet to local host using some dedicated port and do some action. This I can easily do manually. Since I need to fire a lot requests so I would like to optimize it using a shell script to avoid telnetting each... (3 Replies)
Discussion started by: umarsatti
3 Replies

3. Shell Programming and Scripting

shell script to run after ssh logout from another machine

Scenario: I currently manager a cluster at work which is on a private network and i constantly need to ssh to other clients for diags e.t.c. I created a debain client which i use as my gateway to get to all the clients on the private network and I then created a Shell menu script which will make... (4 Replies)
Discussion started by: defamer
4 Replies

4. Shell Programming and Scripting

Telnet using shell script

Hi I need to telnet a device with IP Address and port. After logging in, I need to execute some commands in that device. Please find the example below telnet 170.10.11.1 2100 #170.10.11.1 is the IP address. 2100 is the Port after telnet, the device will show the command prompt as : ... (2 Replies)
Discussion started by: sudharsan23
2 Replies

5. Shell Programming and Scripting

Authenticate Shell script

Hi I want to create a script that will authenticate user from a file and if both of them match then only the script is allowed to be executed... Suppose I have a script say test.sh and a file config.txt for users whose user ids exist in the text file should only be given permission to... (1 Reply)
Discussion started by: ultimatix
1 Replies

6. UNIX for Dummies Questions & Answers

How to authenticate sybase login thru shell script ?

Hi All, This is my first post. Need your favour guys. I need to authenticate syabse login/password thru shell script. I am getting the ID & Pwd form user and storing it in variable.. But how to authenticate and echo user back if the id/pwd doesnt work. isql -U$1 -P$2 -S$3 ?? thanks in... (3 Replies)
Discussion started by: libin4u2000
3 Replies

7. Shell Programming and Scripting

usage of telnet in shell script

Hi All, How could I use telnet to connect to Primary Host in the below shell script: Could I use: ( echo user sleep 2 echo password sleep 2 echo "ls ~" sleep 2 echo "exit" ) | telnet hostname ... (1 Reply)
Discussion started by: a1_win
1 Replies

8. Solaris

using shell script to telnet

I would like to log into a server read a certain file and get the results back. I have tried like below to no avail; #!/bin/ksh -x ( sleep 2 echo sdpuser sleep 2 echo cs3reloaded sleep 5 cd /export/home/scripts/daily_checks sleep 5 head daily_check_report.txt > test160108.txt exit )... (6 Replies)
Discussion started by: ricky katix
6 Replies

9. Linux

Difference between logout from Gnome and Telnet

Hi, I have a java process started as a background job from Gnome Shell and logs out, that process is killed whereas when I started the same process from a telnet console and then logs out of the telnet session, that process is running properly. Can some one guide me with whats actually happening... (5 Replies)
Discussion started by: usureshb
5 Replies

10. Shell Programming and Scripting

telnet & su in shell script

Hi, Any scripting experts out there that can point me to the right direction of writing a script using telnet and su to access a server without any users interaction such as login and entering passwd. Thanks. Thanks in advance vastare (1 Reply)
Discussion started by: vastare
1 Replies
Login or Register to Ask a Question