The code below works well right now; however, it's serially executed. I'd like to be able to roll through the source_list file until I get a max number of sessions and let them all complete and feed the results back to this parent script. Is that possible or would it require me to change the script I'm calling to feed back the results? I've looked at the fork command but it somewhat eludes me.
set source_list [lindex $argv 0]
set device_list [open $source_list r]
while {[gets $device_list ipaddress] != -1} {
spawn "./ios-upgrade.exp" 0 $ipaddress username password image-file MD5hash ftp-server
expect eof
}
close $device_list
All you really need is:
exec ./ios-upgrade.exp 0 $ipaddress username password image-file MD5hash ftp-server &
## No need for an expect statement here since you didn't spawn...
The & character at the end of exec backgrounds the script in the shell so your loop will not be blocked for the return code.
However, you are sending the username and password as CLI args, so they will also show up in the process table when someone does ps auxw or its ilk. I would store the username / passwords in the same file with your IP address, and use:
exec ./ios-upgrade.exp 0 $ipaddress image-file MD5hash ftp-server &
## No need for an expect statement here since you didn't spawn...
After ios-upgrade.exp is done, have it write a file named something like ip_4_1_12_18.out and iterate through the directory until you have received status for all the ip addresses.
OP's additional information:
Turns out the missing piece of information to the above answer was to eval the variable so it was passed properly.
exec ./ios-upgrade.exp 0 {*}$ipaddress image-file MD5hash ftp-server &
*Note that {*} only works with TCL 8.5 and above.
Found the answer in the following: How to add a variable amount of arguments to exec in tcl?
Turns out the missing piece of information to the above answer was to eval the variable so it was passed properly.
exec ./ios-upgrade.exp 0 {*}$ipaddress image-file MD5hash ftp-server &
*Note that {*} only works with TCL 8.5 and above.
Found the answer in the following: How to add a variable amount of arguments to exec in tcl?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With