The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Disconnecting a telnet session cooldude UNIX for Dummies Questions & Answers 14 12-09-2007 04:21 PM
Telnet Session to AIX bluebee UNIX for Dummies Questions & Answers 1 08-07-2007 12:19 PM
Unix Telnet session mlucas UNIX for Dummies Questions & Answers 2 08-17-2006 07:26 AM
Telnet session does not expire deepsteptom Shell Programming and Scripting 1 08-03-2004 08:48 AM
telnet session timeout yls177 UNIX for Dummies Questions & Answers 6 10-16-2002 06:11 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-06-2005
Registered User
 

Join Date: Apr 2005
Posts: 21
Exclamation Telnet Session

{
sleep 2
echo "$user"
sleep 2
echo "$password"
sleep 2
echo " ls"
sleep 10
echo "exit"
}| telnet $server


I have a machine x and i have executed the above script on machine 'x'.
i entered the appropriate user and password in the script and gave the ipaddress of the server in telnet $server.

When i executed this script on machine x, telnet started to another machine, took the user name and password and got logged in. It then executed the "ls" and "exit" commands from the script.

But i removed the exit command and executed the script, I got the prompt on the other machine, but i am not able to execute any commands and the prompt hangs.

HELP ME OUT !!!!!!!!!!!!!!!!!!!!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-06-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 627
your script --- not stdin --- is supplying input to the telnet process so it hangs when you take the exit comand out as telnet is waiting for more input ...
Reply With Quote
  #3 (permalink)  
Old 04-06-2005
Registered User
 

Join Date: Apr 2005
Posts: 21
Exclamation Reply with code

Quote:
Originally Posted by Just Ice
your script --- not stdin --- is supplying input to the telnet process so it hangs when you take the exit comand out as telnet is waiting for more input ...
Please reply me with the modified code if possible !!!!!!!!!
Reply With Quote
  #4 (permalink)  
Old 04-06-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 627
what is the purpose of this script? is this just to help you login without putting in your password? if so, try rlogin (see "man rlogin") or ssh (see man "ssh") ...
Reply With Quote
  #5 (permalink)  
Old 04-06-2005
Registered User
 

Join Date: Apr 2005
Posts: 21
Purpose of this Script

Hi,

This is the purpose of this script.


Everyday, many times i need to log on to a local unix machine first, then use telnet to connect to remote unix machine using the desired username and password.

What my idea is whenever i execute a shell script(contains the ipaddress of remote machine, username, password) on a local unix machine, it gets connected automatically. May be the purpose is not worth but just got eager to know whether it can be done or not.

Thanks in advance if you can post the code or modify the script i have sent.
Reply With Quote
  #6 (permalink)  
Old 04-06-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 627
somebody else might be able to modify your code to do what you want but i think that is a big waste of time as you can definitely use rlogin or ssh to what you need ... good luck!
Reply With Quote
  #7 (permalink)  
Old 04-06-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,355
You could use expect, a bit like this. What you're trying to do is hard. In place of your
echo "exit"
you will need a loop that reads from stdin and writes to the telnet process. The next problem is terminated that loop and the remote shell at once. In the code below, I went with cntl-d. When the user types EOF (usually cntl-d), the loop terminates. Then the remote shell is sent an "exit". You can only send lines to the remote shell this way. No vi. No emacs. So I agree with No Ice, rch or ssh is the way to go. Still here is my code....

Code:
#! /usr/bin/ksh
HOST=xxxxxx
USER=yyyyy
PASSWD=zzzz

exec 4>&1
telnet  >&4 2>&4 |&

print -p open $HOST
sleep 3
print -p $USER
sleep 3
print -p $PASSWD
sleep 3
print -p df -k
sleep 3
while IFS="" read line ; do
        print -p "$line"
done
print -p exit

wait
exit 0
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0