Sponsored Content
Top Forums Shell Programming and Scripting Handle occasional condition in expect script Post 302580657 by varunksharma87 on Friday 9th of December 2011 06:54:02 AM
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..
 

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

9. 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
rrpc_shutdown(3ncs)													       rrpc_shutdown(3ncs)

Name
       rrpc_shutdown - shut down a server

Syntax
       #include <idl/c/rrpc.h>

       void rrpc_$shutdown(handle, status)
       handle_t handle;
       status_$t *status;

Arguments
       handle A remote procedure call (RPC) handle.

       status The completion status.  If the completion status returned in is equal to status_$ok , then the routine that supplied it was success-
	      ful.

Description
       The routine shuts down a server, if the server allows it.  A server can use the routine to allow or disallow remote shutdown.

Diagnostics
       This section lists status codes for errors returned by this routine in

       rrpc_$shutdown_not_allowd
	      You send an request to a server that has not issued an call.

Restrictions
       On the client side, because of the way the calls are defined and implemented in the run-time library you  must  explicitly  call  into  the
       entry  point  vector  table  for  the  interface to send an request across the network. The following is an example of a call that works as
       desired:
       (*rrpc_$client_epv.rrpc_$shutdown)(handle, &status);

       The server side stub routine calls the entry point on behalf of the client.  The results of the call are then passed back to the client.

       Before making the shutdown call, the server must have previously executed the following call:
       rpc_$allow_remote_shutdown((unsigned long) TRUE,NULL,&status);

       If the server has not allowed remote shutdown, the call returns an status code.

Files
See Also
       intro(3ncs), rpc_allow_remote_shutdown(3ncs), rpc_shutdown(3ncs)

															       rrpc_shutdown(3ncs)
All times are GMT -4. The time now is 11:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy