shell - spawn后如何在expect shell脚本中获取子进程pid

标签 shell expect spawn

部分脚本 a.exp :

#!/usr/bin/expect
# ..... 
spawn ssh -qTfnN -D $port $user@$host
expect "*assword:*"
# .....

我如何获得 pid 子进程“ssh”。

如果我在 bash shell 中执行这些,而不是在脚本文件中,结果是
expect1.1> spawn ssh name@host
spawn ssh name@host
2188
expect1.2> 

2188 是子进程pid。

以及如何使用 exp_pid 在expect shell中的命令?

最佳答案

我认为你正在寻找的是这样的:

spawn ssh name@host
set pid [exp_pid]
puts "PID: $pid"

关于shell - spawn后如何在expect shell脚本中获取子进程pid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9260633/

相关文章:

linux - 在日志中提供 Control M 的重定向

php - 如何在 Apache2 中用 php 执行 shell 脚本?

bash - 期望通过 ssh 提示脚本更改密码

bash - 从 crontab 中调用执行期望的 bash 脚本

ruby-on-rails - Rails 应用程序 : Reconnect juggernaut redis after forking?

child_process.spawn 上的 node.js EPIPE 异常

shell - 在 Jenkins 中构建后执行 Shell 脚本

python - 即使在其中的命令退出后继续 for 循环

amazon-web-services - EC2上的运行Expect脚本挂起,但是在手动调用时成功运行

node.js - child_process.spawn 仅在命令完成时立即返回 stdout,但在执行期间不会分块返回