Expect中的并行处理

时间:2012-06-15 00:35:41

标签: tcl expect

以下代码现在运作良好;然而,它是连续执行的。我希望能够遍历source_list文件,直到我获得最大数量的会话并让它们全部完成并将结果反馈给此父脚本。这是可能的还是需要我更改我要调用的脚本来反馈结果?我看过fork命令,但它有点让我失望。

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

2 个答案:

答案 0 :(得分:1)

你真正需要的是:

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

&末尾的exec字符表示shell中的脚本,因此不会阻止循环返回代码。

但是,您要将用户名和密码作为CLI args发送,因此当有人ps auxw或其同类时,它们也会显示在流程表中。我会将用户名/密码与您的IP地址存储在同一个文件中,并使用:

exec ./ios-upgrade.exp 0 $ipaddress image-file MD5hash ftp-server &
## No need for an expect statement here since you didn't spawn...

完成ios-upgrade.exp后,让它写一个名为ip_4_1_12_18.out的文件并遍历目录,直到收到所有IP地址的状态。


OP的附加信息:

原来上面的答案中缺少的信息就是评估变量,以便正确传递。

exec ./ios-upgrade.exp 0 {*}$ipaddress image-file MD5hash ftp-server &

*请注意,{*}仅适用于TCL 8.5及更高版本。

找到以下答案:How to add a variable amount of arguments to exec in tcl?

答案 1 :(得分:1)

原来上面的答案中缺少的信息就是评估变量,以便正确传递。

exec ./ios-upgrade.exp 0 {*}$ipaddress image-file MD5hash ftp-server &

*请注意,{*}仅适用于TCL 8.5及更高版本。

找到以下答案:How to add a variable amount of arguments to exec in tcl?