![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
{
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 !!!!!!!!!!!!!!!!!!!! |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
|
|
|||
|
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. |
|
||||
|
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
|
||||
| Google UNIX.COM |