Handle occasional condition in expect script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Handle occasional condition in expect script
# 1  
Old 12-09-2011
Handle occasional condition in expect script

Hi,

I am using Solaris OS,
I want to handle an occasional expression in expect script while logging into a remote server with ssh.

In normal scenario the expected expression is as below,
spawn ssh $user@$ip
expect "assword:"
send "$password\r"


but in a condition when the remote server is not in the known hosts of local server, the server prompts if you want to add the remote server as known host ending with an expression (yes/no).
i have got below code to handle that condition but it is failing.
spawn ssh $user@$ip
expect "(yes/no)?"
send -- "yes\r"

expect "assword:"
send "$password\r"


can somebody suggest a better way to handle that.

As i mentioned earlier my problem is that (yes/no) expression is occasional that is whenever the remote server has got rebooted or something. Otherwise the normal password prompt comes.

Its something like, i want

if remote server prompts,(yes/no)
pass:-yes
and continue with password passing

if remote server doesn't prompt,(yes/no)
just continue with password passing


Thanks in advance.

Moderator's Comments:
Mod Comment Please use

code tags!

Last edited by vbe; 12-09-2011 at 09:49 AM..
# 2  
Old 12-09-2011
Hi,

i never use expect so i can't help you on this, but there another way to solve that.

Use the call
Code:
ssh -o StrictHostKeyChecking=no $user@$ip

This way it will never ask you and auto add all new hosts.
This User Gave Thanks to Chirel For This Post:
# 3  
Old 12-10-2011
Network

Thanks Chirel, Yes that can help me out.
Can anybody else help in making an expect script for my problem.?
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

2. 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

3. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

4. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

5. Shell Programming and Scripting

How to handle scripts that expect an input

Hi I would like to know how to handle my script that expects an input when calling the script and the user doesn't enter anything, I need to re-direct to my helpfile. Bascically here is my script: #!/bin/bash csvdir="/var/local/dsx/csv/general" csvfile="$csvdir/$csvfile"... (3 Replies)
Discussion started by: ladyAnne
3 Replies

6. Shell Programming and Scripting

help to handle the expect script issue

Hi experts I know the expect script can match the terminal output to run the the following cmd I write a script with expect named "test", I want to run ten "test" with background running, for ((i=1;i<=10;i++) do ./test -n $i done I find all the output of test will print on one... (0 Replies)
Discussion started by: yanglei_fage
0 Replies

7. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

8. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

9. Shell Programming and Scripting

how do I handle ssh response with expect

I am trying to write an expect script that trys to telnet, if telnet fails, trys to ssh to a remote network devices. The script works fine until the following is received : spawn telnet 10.3.2.24 Trying 10.3.2.24... telnet: connect to address 10.3.2.24: Connection refused 10.3.2.24 is... (2 Replies)
Discussion started by: popeye
2 Replies
Login or Register to Ask a Question