How to extract an ipaddress and use it in for loop in expect script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract an ipaddress and use it in for loop in expect script?
# 1  
Old 05-09-2014
How to extract an ipaddress and use it in for loop in expect script?

Code:
set fid [open ./hosts r]
set content [read $fid]
close $fid

## Split into records on newlines
set records [split $content "\n"]
send "records splited\n"
send $records\n

set a "test\n"
send $a
foreach rec $records { 

   ## Split into fields on colons
   set fields [split $rec "\n"]
#set fields [split $records "\n"]
puts $fields

for {set x 1} {$x < 4} {incr x} {
  spawn ssh root@$fields
 expect "*yes/no*" { send "yes\r"}
   expect "*password:*" { send "redhat\r" }
   expect "*#*" { send "exit\r" }
   expect eof
   puts "$a"
}
}


Last edited by joeyg; 05-09-2014 at 08:52 AM.. Reason: Please wrap commands inside CodeTags
# 2  
Old 05-09-2014
...and is there a question, comments or just a code dump waiting for a miraculous response answering your unexplained issue?
This User Gave Thanks to rbatte1 For This Post:
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

Expect Script - Not Seeing Output from While Loop

I know something simple is missing here, "log_user 1" is set . . . after this utility opens ${InFile} (handle? for IntInFile) it needs to look for something to appear in the file ${IntInFile} and then send it to the spawned process. Then I am locking the file ${IntInFile} and clearing it out -... (0 Replies)
Discussion started by: JuanMatteo
0 Replies

3. Shell Programming and Scripting

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (14 Replies)
Discussion started by: thisissouvik
14 Replies

4. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

5. Shell Programming and Scripting

Expect script called in loop from Bash Script

Having issues with an expect script. I've been scripting bash, python, etc... for a couple years now, but just started to try and use Expect. Trying to create a script that takes in some arguments, and then for now, just runs a pwd command(for testing, final will be command I pass). Here is... (0 Replies)
Discussion started by: cbo0485
0 Replies

6. Shell Programming and Scripting

expect script pushing ssh keys w/ tar extract

ok, I'm new to the forum and I did a few searches and didn't find much on this so here goes. I have a ksh I use to call an expect script that opens a ssh session and then extracts a tar file. The tar file has my prefered .profile and my ssh keys. I want to run this script 1 time on new servers and... (2 Replies)
Discussion started by: gtsonoma
2 Replies

7. Shell Programming and Scripting

Replacing the ipaddress using script

Hi all , I have written the script but the ip address is not getting replaced correct me i ima wrong #!/bin/bash echo "enetr ip" read $a echo $a b=`grep -o '\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}' /usr/local/kalyan/mysqlup.sh` echo "$b" sed -i 's/'$b'/'$a'/g' /usr/local/kalyan/mysqlup.sh ... (1 Reply)
Discussion started by: kalyankalyan
1 Replies

8. Shell Programming and Scripting

Expect - Comparison of expect value and loop selection

Hello All, I am trying to automate an installation process using expect and sh script. My problem is that during the installation process the expected value can change according to the situation. For Example if this is a first time installation then at step 3 I'll get "Do you want to accept... (0 Replies)
Discussion started by: alokrm
0 Replies

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

10. 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
Login or Register to Ask a Question