expect ssh script cannot finish and exit

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expect ssh script cannot finish and exit
# 1  
Old 07-22-2011
expect ssh script cannot finish and exit

i am new to linux, and try to have a simple expect script to ssh then telnet to the network equipment, and exit itself. but dont know why i hang at the last $

set timeout 10

set arg [lindex $argv 0]
set arg1 [lindex $argv 1]

spawn ssh -l UserA
expect "assword:";
send "PasSwOrD\r";
expect "$";
send "telnet\r";
set timeout 260
expect "login:";
send "UserA\r";
expect "Password:";
send "PasSwOrD\r";
expect ">";
send "exit\r";
expect "$";
send "exit\r";

expect eof


[root@sam BUM]# ./testtelnet
spawn ssh -l UserA
UserA@'s password:
Last login: Sat Jul 23 08:23:57 2011 from x.x.x.x
Sun Microsystems Inc.   SunOS 5.8       Generic Patch   October 2001
Could not chdir to home directory /home/UserA: No such file or directory
Sun Microsystems Inc.   SunOS 5.8       Generic Patch   October 2001
$ telnet
Connected to
Escape character is '^]'.

Host2 (ttyp0)

login: Password:

--- JUNOS 10.4 built 2011-05-27 07:22:52 UTC
UserA@Host2> exit

Connection closed by foreign host.


then hanging there and no response...
how i can end this correctly ?

thanks a lot everyone

Last edited by pludi; 07-23-2011 at 09:03 PM..
# 2  
Old 08-31-2011
I'm not sure, but possibly the "$" is taken in some special meaning. Try
expect -ex "\$"

In any case you may get more insight into the script's operation by adding
exp_internal 1

at the beginning
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make expect exit the UNIX script in erreneous condition

Hi, I am writing a menu driven program using shell script. THe script will be collecting data by logging into the other servers and bringing back the data to home server to process it and accordingly issue commands. TO automate commands execution , I am using expect script. However I am not able... (5 Replies)
Discussion started by: ashima jain
5 Replies

2. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

3. Shell Programming and Scripting

How to test for the ssh exit status in script?

Hello; I regularly run monitoring scripts over ssh to monitoring scripts But whenever a server is hung or in maintenance mode, my script hangs.. Are there anyways to trap exit status and be on my way ?? Looked at the ssh manpage and all I can see is a "-q" option for quiet mode .. Thank... (2 Replies)
Discussion started by: delphys
2 Replies

4. Shell Programming and Scripting

Script using SSH with expect command

Hi all, I want to connect to some host with "ssh". I have googled and got some commands of "expect" and "spawn". I was not aware of these commands and tried below script. $ cat auto.sh set host xx.xx.xx.xx set password abcd@1234 set user root spawn ssh $user@$host expect "*?assword:*"... (4 Replies)
Discussion started by: divya bandipotu
4 Replies

5. Shell Programming and Scripting

Expect script: obtain the exit code of remote command

Hi all, I'm trying to run the sipp simulator in crontab but after some attempt I came to the conclusion that for some reason this isn't possible (maybe due to sipp interactive nature). This is confirmed by these posts. Now I'm trying to launch sipp from an expect script that runs in crontab. ... (0 Replies)
Discussion started by: Evan
0 Replies

6. Shell Programming and Scripting

Expect Script to Automate SSH

How would I write an expect script to automate ssh and what file extention do expect files use? (11 Replies)
Discussion started by: Prodiga1
11 Replies

7. UNIX for Advanced & Expert Users

Multiple ssh, shutdown and exit script

PROBLEM: I need to ssh into multiple remote machines, send a shutdown command and exit. The remote servers will then run their own scripts to gracefully shutdown their applications before shutting down. ONE: This is to be achieved without using public key authentication; this is being avoided... (2 Replies)
Discussion started by: ulemsee
2 Replies

8. Shell Programming and Scripting

SSH Expect Script

Ok, i don't know if anyone else here have had to deal with something like this before, but here's my situation. I have about 1000+ servers I need to log into to do something. What i need to do is to log into each server, go to a certain directory on each of the servers, copy the files that... (3 Replies)
Discussion started by: SkySmart
3 Replies

9. Shell Programming and Scripting

Expect script to ssh into MMI

Guys, I know this is tricky.. I'm trying to write a script to pull info from a MMI device. Following script logins into the server and then changes to super user. Opens MMI session and then exits out. I need to run the command under the MMI session "dsp_alarm_span all" Is there any other way to... (2 Replies)
Discussion started by: miltonrods
2 Replies

10. Shell Programming and Scripting

check exit status - Expect Script

from my main script, i am calling an expect script. there are a lot of conditions in the Expect script and it can have any exit value based on success or failure of the Expect Script. how can i check the exit status of Expect scritp in the main script. (1 Reply)
Discussion started by: iamcool
1 Replies
Login or Register to Ask a Question