Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 157

How to increment for loop by 2 in Expect script?

$
0
0

I have this piece of code in bash script which is working perfectly fine and increment the variable by one. I want to be able to increment by two so that there are two registrations happening at once in parallel. Below is the piece of code for expect:

/usr/bin/expect << 'EOF2'set tarts [split $env(Tarts)]set ips [split $env(IPs)]puts "Tarts to be updated: $tarts"puts "IPs of Tarts: $ips"for { set index 0 } { $index < [llength $tarts] } { incr index } {puts "In Loop: $index"set tart [lindex $tarts $index]puts "TARTS Num: $tart"set ip [lindex $ips $index]puts "IP: $ip"puts "``````````````````````````````````````````````````````````````"puts "Registering Stations on Tarts"puts "``````````````````````````````````````````````````````````````"        spawn telnet $ip 6187        set timeout -1        expect {"*traffic*" {                puts "``````````````````````````````````````````````````````````````"                puts "Registering Group1, Group2 of Tart#: [lindex $tart $index]"                send "traffic map rate reg_group1 30000\r"                send "traffic map rate reg_group2 30000\r"                puts "wait 300 seconds .."                send "traffic go\r"                sleep 300                 sleep 2                puts "``````````````````````````````````````````````````````````````"                puts "Setting hold_time for 4kagents to 20000s"                puts "traffic map param 4kagents hold_time=20000"                send "traffic map param 4kagents hold_time=20000\r"                puts "traffic map param 4kagents hold_time=20000"                send "traffic map param 4kagents hold_time=20000\r"                puts "wait 5 seconds .."                sleep 5                puts "``````````````````````````````````````````````````````````````"                puts "``````````````````````````````````````````````````````````````"                sleep 2                puts "``````````````````````````````````````````````````````````````"                puts "Logging in Agents using map 4kagents on Tart#: [lindex $tart $index]"                puts "traffic map param 4kagents 1"                send "traffic map param 4kagents 1\r"                puts "wait 120 seconds .."                sleep 120                puts "``````````````````````````````````````````````````````````````"                puts "``````````````````````````````````````````````````````````````"                }                puts "wait 3 seconds"                sleep 3                send -- "^]"                expect -exact "^\]\rtelnet> "                send -- "close\r"                expect eof        }}EOF2

I have tried incrementing the variable by 1 like set tarts [split $env(Tarts) + 1] / set ips [split $env(IPs) + 1] but I am getting syntax errors. I have also tried doing for { set index 0 } { $index < [llength $tarts] } { incr index 2 } but doesn't work. Can someone guide please?


Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>