Bash 期望同一进程中有两个命令
Bash expect two commands in same process
我正在疯狂地尝试让它发挥作用。
我需要使用 expect 来设置几个密码。我遇到的问题是我必须在同一个处理器中使用 运行 两个命令。
代码在这里
yum install -y expect
secret="price_aws_git_secret.txt"
eval $(ssh-agent)
pass=$(cat $secret)
expect << EOF
spawn ssh-agent ssh-add price_aws_github
expect "Enter passphrase"
send "$pass\r"
spawn git clone git@github/repo.git
expect "Are you sure you want to continue connecting"
send "yes\r"
expect eof
EOF
第一个命令将 ssh 密钥添加到 ssh-agent 中,第二个命令 git 克隆需要在同一进程中才能获取该代理。
查看文档和示例我看不出 expect 如何在同一进程中使用两个命令。
有什么建议吗?
谢谢!
关于更好地使用 ssh 密钥的建议放在一边,回答你的问题。您不需要同时与两个进程交互。您需要处理第一个,然后开始第二个:
expect << EOF
spawn ssh-agent ssh-add price_aws_github
expect "Enter passphrase"
send "$pass\r"
# assume this works. if not, there's more work to do
expect eof
close
spawn git clone git@github/repo.git
expect "Are you sure you want to continue connecting"
send "yes\r"
expect eof
EOF
我正在疯狂地尝试让它发挥作用。
我需要使用 expect 来设置几个密码。我遇到的问题是我必须在同一个处理器中使用 运行 两个命令。
代码在这里
yum install -y expect
secret="price_aws_git_secret.txt"
eval $(ssh-agent)
pass=$(cat $secret)
expect << EOF
spawn ssh-agent ssh-add price_aws_github
expect "Enter passphrase"
send "$pass\r"
spawn git clone git@github/repo.git
expect "Are you sure you want to continue connecting"
send "yes\r"
expect eof
EOF
第一个命令将 ssh 密钥添加到 ssh-agent 中,第二个命令 git 克隆需要在同一进程中才能获取该代理。
查看文档和示例我看不出 expect 如何在同一进程中使用两个命令。
有什么建议吗?
谢谢!
关于更好地使用 ssh 密钥的建议放在一边,回答你的问题。您不需要同时与两个进程交互。您需要处理第一个,然后开始第二个:
expect << EOF
spawn ssh-agent ssh-add price_aws_github
expect "Enter passphrase"
send "$pass\r"
# assume this works. if not, there's more work to do
expect eof
close
spawn git clone git@github/repo.git
expect "Are you sure you want to continue connecting"
send "yes\r"
expect eof
EOF