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:
The
&character at the end ofexecbackgrounds 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 auxwor its ilk. I would store the username / passwords in the same file with your IP address, and use:After
ios-upgrade.expis done, have it write a file named something likeip_4_1_12_18.outand 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.
*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?