expect script, how to deal with different outputs.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expect script, how to deal with different outputs.
# 1  
Old 05-21-2010
expect script, how to deal with different outputs.

I have an expect script that I need to deal with a few different outputs? Here are the commands I am running

ssh -o StrictHostKeyChecking=no root@$ipaddress "racadm config -g cfgIpmiLan -o cfgIpmiLanEnable 1"

Now, the system I am running this from if I have connected to the server before I immediately get the password prompt; if not I get an addition message "Warning: Permanently added '10.183.188.15' (RSA) to the list of known hosts."

How can I handle getting that message? Im not too familiar with tcl scripting so Im not sure how to look for that message and ignore it.

Oh, and ssh keys are not an option asdell drac's dont have any type of keygen or .ssh/authorized_keys directory that I know of. Besides that I would still need an expect script to get them initially setup Smilie

Code:
#!/usr/bin/expect -f

set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]

set timeout -1
spawn ssh -o StrictHostKeyChecking=no root@$ipaddress {racadm config -g cfgIpmiLan -o cfgIpmiLanEnable 1}
match_max 100000
expect -exact "root@$ipaddress password: "
send -- "$passwd\r"
expect eof



---------- Post updated 05-21-10 at 08:36 AM ---------- Previous update was 05-20-10 at 10:05 AM ----------

ok, lots of googling and I found an answer...

this is basically an expect case/loop thingy...

Code:
#!/usr/bin/expect -f

set ipaddress [lindex $argv 0]
set passwd [lindex $argv 1]

set timeout -1
spawn ssh -o StrictHostKeyChecking=no root@$ipaddress {racadm config -g cfgIpmiLan -o cfgIpmiLanEnable 1}
expect { 
  "Warning: *" {
     exp_continue
  }
  "root@${ipaddress}'s password: " {
  send "${passwd}\r"
  }
}

expect eof

exp_continue, continues the loop/case thing to look for more matches...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 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

Script to check for few conditions and respond with outputs

All, Here is what I am trying to accomplish: 1. Check for a file of specific name recursively and when I find it, a. if the file is more than 1hr old, no need to email or send notification, so just exit out from the shell script b. if the file is less than 1hr old, send an email to me saying... (3 Replies)
Discussion started by: pnara2
3 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

Assign specific Color to the outputs in script

Hi, Im programming an interactive menu that verifies the exports of my oracle DB, and im having some trouble finding a process that outputs for example a green command line when the export terminated successfully. i have something like this cat... (15 Replies)
Discussion started by: blacksteel1988
15 Replies

6. Shell Programming and Scripting

create outputs from other command outputs

hi friends, The code: i=1 while do filename=`/usr/bin/ls -l| awk '{ print $9}'` echo $filename>>summary.csv #Gives the name of the file stored at column 9 count=`wc -l $filename | awk '{print $1}'` echo $count>>summary.csv #Gives just the count of lines of file "filename" i=`expr... (1 Reply)
Discussion started by: rajsharma
1 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

Script that takes in variables, and outputs to another text or script file

Ok, I sort of need to create a command files that will be ftped to another server to run. I have some input variable that will need to be read, and then transformed into another script file. Here are some examples. Server 1: outputCmd.sh passing in ./outputCmd.sh nh8oaxt Release_4_0... (1 Reply)
Discussion started by: orozcom
1 Replies

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

10. Shell Programming and Scripting

problems with a script that outputs data to a file

First of all, im a total newbie to the point that i do not know what are the terms to search for my problem. I did however spend the rest of the day today trying to figure out what is wrong with my bash script. ive always thought that the best way to learn is to tackle a problem heads on. but at... (1 Reply)
Discussion started by: joeribut
1 Replies
Login or Register to Ask a Question