Sponsored Content
Top Forums Shell Programming and Scripting How to extract an ipaddress and use it in for loop in expect script? Post 302900870 by rachanaPatel on Friday 9th of May 2014 07:28:43 AM
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
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
configbody(n)							    [incr Tcl]							     configbody(n)

NAME
configbody - change the "config" code for a public variable SYNOPSIS
configbody className::varName body DESCRIPTION
The configbody command is used outside of an [incr Tcl] class definition to define or redefine the configuration code associated with a public variable. Public variables act like configuration options for an object. They can be modified outside the class scope using the built-in configure method. Each variable can have a bit of "config" code associate with it that is automatically executed when the vari- able is configured. The configbody command can be used to define or redefine this body of code. Like the body command, this facility allows a class definition to have separate "interface" and "implementation" parts. The "interface" part is a class command with declarations for methods, procs, instance variables and common variables. The "implementation" part is a series of body and configbody commands. If the "implementation" part is kept in a separate file, it can be sourced again and again as bugs are fixed, to support interactive development. When using the "tcl" mode in the emacs editor, the "interface" and "implementation" parts can be kept in the same file; as bugs are fixed, individual bodies can be highlighted and sent to the test application. The name "className::varName" identifies the public variable being updated. If the body string starts with "@", it is treated as the sym- bolic name for a C procedure. Otherwise, it is treated as a Tcl command script. Symbolic names for C procedures are established by registering procedures via Itcl_RegisterC(). This is usually done in the Tcl_AppInit() procedure, which is automatically called when the interpreter starts up. In the following example, the procedure My_FooCmd() is registered with the symbolic name "foo". This procedure can be referenced in the configbody command as "@foo". int Tcl_AppInit(interp) Tcl_Interp *interp; /* Interpreter for application. */ { if (Itcl_Init(interp) == TCL_ERROR) { return TCL_ERROR; } if (Itcl_RegisterC(interp, "foo", My_FooCmd) != TCL_OK) { return TCL_ERROR; } } EXAMPLE
In the following example, a "File" class is defined to represent open files. Whenever the "-name" option is configured, the existing file is closed, and a new file is opened. Note that the "config" code for a public variable is optional. The "-access" option, for example, does not have it. class File { private variable fid "" public variable name "" public variable access "r" constructor {args} { eval configure $args } destructor { if {$fid != ""} { close $fid } } method get {} method put {line} method eof {} } body File::get {} { return [gets $fid] } body File::put {line} { puts $fid $line } body File::eof {} { return [::eof $fid] } configbody File::name { if {$fid != ""} { close $fid } set fid [open $name $access] } # # See the File class in action: # File x x configure -name /etc/passwd while {![x eof]} { puts "=> [x get]" } delete object x KEYWORDS
class, object, variable, configure itcl 3.0 configbody(n)
All times are GMT -4. The time now is 03:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy