Need Help with expect when ssh fails


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help with expect when ssh fails
# 1  
Old 04-06-2010
Need Help with expect when ssh fails

I'm trying to write a script using expect. I'd like the script to execute several commands when the ssh succeeds and i want it to exit if the ssh fails. Does this require to define a time out for the ssh command so that if the prompt is back before this defined time the next commands are executed??

Another question: Is there a way to direct the script to skip some lines when ssh fails and start execution from certain line?

Thanks in advance
# 2  
Old 04-06-2010
In general you can have expect wait a certain amount of time before it goes on to try and run the next command.

I did something similar with an expect script that logs into our switches at work, and uploads the configs. For example, the script looks to see if you are asked to accept the host key, so the line for expect says:

Code:
# Look for unknown Host Keys question and reply with yes:
expect -timeout 10 "yes/no" {send "yes\r"}

After connecting the script will wait 10 seconds to see the yes/no...if it doesn't see it, it moves on.

Hope that helps
# 3  
Old 04-07-2010
Thanks alot...but let me tell you more details about the peoblem i'm facing.
I'm using the below code

spawn ssh mxadmin@$ip
expect {
"yes/no" {send "yes\r"}
Connection timed out {break}
eof {exit }
}


--some more commands--
My problem is that when ssh fails: the commands continue execution without so the break command did not prevent the expect file from being completed.

Thanks in advance
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ssh fails from one server only with expecting SSH2_MSG_KEXDH_REPLY message

I have two linux servers viz 12.7.44.18 and 12.7.45.18 I wish to ssh from both these server to a destination AiX server 12.7.33.18 The ssh works from 12.7.44.18 -> 12.7.33.18 but fails from 12.7.45.18 -> 12.7.33.18 The openssl version on both linux source 12.7.44.18 and 12.7.45.18 is the... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

Ssh fails for one of two users on the same server.

I have two users on dest_host server viz wlsadm & wasadm. From src_host server with root user I m able to passwordless login to wlsadm@dest_host however, the same fails for wasadm@dest_host Below is the debug for both first the working ssh and then the non-working ssh. Works: ... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. Shell Programming and Scripting

Ssh fails due to argument position.

I have a constraint to follow organization policy. So i do not have much liberty. ssh -i /opt/nonprod user1@hostone -t bash works while ssh -i /opt/nonprod -t bash user1@hostone fails How can I get this to work when I am enforced to put -t bash before the user@hostname ? Will share debug... (3 Replies)
Discussion started by: mohtashims
3 Replies

4. Shell Programming and Scripting

Windows exe file fails when triggered from ssh

Hi, I am triggering a windows exe file using the below command. ssh user@remoteserver command.exe -option1:xx /option2:yy This command is working fine from windows command prompt. When I am triggering the same command from ssh I get the error message cant load Any ideas to deal with... (2 Replies)
Discussion started by: ahmedwaseem2000
2 Replies

5. Shell Programming and Scripting

While loop not reading all files if ssh fails

The below while loop is in ksh on a SunOs server: SPARC-Enterprise 5.10 The ksh version is: Version M-11/16/88i The intention of the below while loop is to read through a list of file names in files.txt and delete each file from a server, one at a time. The delete works, the problem is that if... (6 Replies)
Discussion started by: LES2013
6 Replies

6. Shell Programming and Scripting

Ssh = ssh expect and keep everything not change include parameter postion

I have write a script which contains ssh -p 12345 dcplatform@10.125.42.50 ssh 127.0.0.1 -p 5555 "$CMD" ssh root@$GUEST_IP "$CMD" before I use public key, it works well, now I want to change to "expect", BUT I don't want to change above code and "parameter position" I can post a... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

7. Ubuntu

Passwordless ssh authentication fails

Unable to set ssh passwordless authentication I am unable to ssh with passwordless authentication from Windows client onto UBuntu server. The ssh version on UBuntu is OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e , while SSH on Windows Client is OpenSSH_5.1p1, OpenSSL 0.9.8k. I turned on ssh... (5 Replies)
Discussion started by: tkota
5 Replies

8. Shell Programming and Scripting

Help needed with expect...(If telnet fails)

Hello I'm working using expect to automate telnet commands...i want to check if telnet fails and in this case...certain message should appear or certain word should be out in a file). Thses are the messages that apeear if telnet fails: Trying 172.16.3.115... telnet: Unable to connect... (0 Replies)
Discussion started by: Hossam_Nox
0 Replies

9. Shell Programming and Scripting

could not send commands SSH session with Net::SSH::Expect

I am using Net::SSH::Expect to connect to the device(iLO) with SSH. After the $ssh->login() I'm able to view the prompt, but not able to send any coommands. With the putty I can connect to the device and execute the commands without any issues. Here is the sample script my $ssh =... (0 Replies)
Discussion started by: hansini
0 Replies

10. Shell Programming and Scripting

unzip command fails in ssh

I'm trying to run a set of commands on a remote machine using ssh in a shell script. One of the commands is unzip. But when the execution reaches this command, the script fails with an error that unzip is not found. Below is the code and the error snippet. sourceDir=$1 ; filename=$3 ; destDir=$2... (4 Replies)
Discussion started by: farahzaiba
4 Replies
Login or Register to Ask a Question