Sponsored Content
Full Discussion: expect question
Top Forums UNIX for Dummies Questions & Answers expect question Post 302251661 by pbaets01 on Monday 27th of October 2008 04:38:28 PM
Old 10-27-2008
Question expect question

I am trying to write a script that telnets out to multiple ip's, runs some commands exits and the telnets to the next ip. I wrote the following script and it works great until the program hits a nonresponsive ip.
I would like this to recognize the ip is bad and move on in the foreach loop. How do I do that?

Any ideas or suggestions are much appreciated.

Here is my script:

#!/opt/bsmext/bin/expect


spawn ssh -l username ip

expect ":"

send "password\r"

expect "$"

foreach ip $argv {
for {set ip 1} {$ip <=120} {incr ip 1} {

expect "$"

send "ssh -l default 10.x.xxx.$ip\r"

expect "password:"


send "xxxxx\r"

expect ">"

send "en\r"

expect "#"

send "xxxxxxxx\r"

expect "#"

send "xxxxxxxx \r"

expect "#"

send "xxxxxxx \r"

expect "#"

send "exit \r"

expect ">"

send "exit \r"

sleep 5

}
}
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

question regarding EXPECT

I am rather new to using expect and have only written a few scripts using it. I am trying to create a script that will read a file containing a number of hostnames and then for each one: ssh into the box, run a command, scp the output back to a center server. So far I can make all that... (2 Replies)
Discussion started by: finnje
2 Replies

2. Shell Programming and Scripting

Question about an expect script

I am using Expect to spawn a command that loops through a text file and runs the same command for each item in the text file. The text file, named stat.txt looks something like this: 2007-04 alist 543 2008-07 blist 543 2008-03 xlist 345 2008-03 ylist 675 2003-03 zlist 567 The expect... (1 Reply)
Discussion started by: manouche
1 Replies

3. Shell Programming and Scripting

Expect question

Hi all, I have got a small expect script like this one. #!/usr/bin/expect -f set timeout 2 spawn ftp $env(IP) match_max 100000 expect -exact "Name" send -- "$env(USER)\n" expect -exact "Password:" send -- "$env(PASSWORD)\n" expect "%" send "bin\r" expect "%" send "prompt\r"... (5 Replies)
Discussion started by: stinkefisch
5 Replies

4. Shell Programming and Scripting

two question about expect srcipt

Hi experts, I have two question about expect script questions 1 send "tar -xjvf a.tar\r" send "ifconfig\r" I want to know if it just run "ifconfig after "tar -xjvf a.tar complete. or the two cmd run at the same time question 2 after I use the expect to ssh to the... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

5. Shell Programming and Scripting

Noob Expect Scripting Question

I'm having some difficulty with convincing Expect to do what I need.. I have a loop that waits for input, a specific phrase of text followed by a single word. I need Expect to capture that word following the specific phrase. It should then store the word in a variable. I'm fairly sure it's... (6 Replies)
Discussion started by: LongLeafTea
6 Replies

6. Shell Programming and Scripting

Question to gurus with expect

Hi., I need to ask question for expect script. I have prompt like # and very long script (orachk). I added to expect script line set prompt "(%|#|\\\$) $" and insert into it also piece of code ---- expect { timeout { puts "Running..." exp_continue } ... (0 Replies)
Discussion started by: beckss
0 Replies

7. UNIX for Beginners Questions & Answers

Expect question

I have an expect script that appears to be working normally however for some reason, the remote side appears to be stripping off the variables from the awk command. This is the original: expect \"~]$\" send \"sed 's/=/ /g;s/,/ /g' /home/file.txt | grep abc | awk '{print $6,$8}'This is the... (5 Replies)
Discussion started by: jimmyf
5 Replies

8. UNIX for Beginners Questions & Answers

Expect Question

Have an expect script but can't seem to de-bug it. It's stalling at the password prompt. If anyone can see a mistake, kindly let me know. Thanks. Here is the error: spawn ssh -o StrictHostKeyChecking=no user@xx.xx.xx.xx rpm -qa # Warning! You have entered into a secured area! # # All... (2 Replies)
Discussion started by: jimmyf
2 Replies

9. UNIX for Beginners Questions & Answers

Expect Question

I'm using expect to log into a remote host and then execute another script. A log of the script is being created but I can't see to get the script to display while it's running. Any ideas would be appreciated. Here is the script. #!/bin/bash cd /root cat /root/hostname1.txt | while read... (1 Reply)
Discussion started by: jimmyf
1 Replies
foreach(n)						       Tcl Built-In Commands							foreach(n)

__________________________________________________________________________________________________________________________________________________

NAME
foreach - Iterate over all elements in one or more lists SYNOPSIS
foreach varname list body foreach varlist1 list1 ?varlist2 list2 ...? body _________________________________________________________________ DESCRIPTION
The foreach command implements a loop where the loop variable(s) take on values from one or more lists. In the simplest case there is one loop variable, varname, and one list, list, that is a list of values to assign to varname. The body argument is a Tcl script. For each element of list (in order from first to last), foreach assigns the contents of the element to varname as if the lindex command had been used to extract the element, then calls the Tcl interpreter to execute body. In the general case there can be more than one value list (e.g., list1 and list2), and each value list can be associated with a list of loop variables (e.g., varlist1 and varlist2). During each iteration of the loop the variables of each varlist are assigned consecutive values from the corresponding list. Values in each list are used in order from first to last, and each value is used exactly once. The total number of loop iterations is large enough to use up all the values from all the value lists. If a value list does not contain enough elements for each of its loop variables in each iteration, empty values are used for the missing elements. The break and continue statements may be invoked inside body, with the same effect as in the for command. Foreach returns an empty string. EXAMPLES
The following loop uses i and j as loop variables to iterate over pairs of elements of a single list. set x {} foreach {i j} {a b c d e f} { lappend x $j $i } # The value of x is "b a d c f e" # There are 3 iterations of the loop. The next loop uses i and j to iterate over two lists in parallel. set x {} foreach i {a b c} j {d e f g} { lappend x $i $j } # The value of x is "a d b e c f {} g" # There are 4 iterations of the loop. The two forms are combined in the following example. set x {} foreach i {a b c} {j k} {d e f g} { lappend x $i $j $k } # The value of x is "a d e b f g c {} {}" # There are 3 iterations of the loop. SEE ALSO
for(n), while(n), break(n), continue(n) KEYWORDS
foreach, iteration, list, looping Tcl foreach(n)
All times are GMT -4. The time now is 02:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy