我想使用一个期望或 Pexpect 文件来自动化一个 shell 命令,例如:
for host in HostList:
ssh -t kitty@host 'sudo nohup bash -c "./tcp_sender > /dev/null 2>&1 &"'
如果我手动输入命令,情况2有 3 种可能性,我必须输入 a yes
,对于其他情况我不需要输入任何内容,不需要密码。
1)
[kitty@goeland kitty]$ ssh -t kitty@202.171.61.205 'sudo nohup bash -c "./tcp_sender > /dev/null 2>&1 &"'
nohup: ignoring input and appending output to `nohup.out'
Connection to 202.171.61.205 closed.
2)
[kitty@goeland kitty]$ ssh -t kitty@202.171.61.205 'sudo nohup bash -c "./tcp_sender > /dev/null 2>&1 &"'
The authenticity of host '202.171.61.205 (202.171.61.205)' can't be established.
RSA key fingerprint is ff:0b:9c:a9:72:52:8f:53:0d:04:d5:ea:d9:3c:56:37.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '202.171.61.205' (RSA) to the list of known hosts.
nohup: ignoring input and appending output to `nohup.out'
Connection to 202.171.61.205 closed.
3) 不同的错误,目前我还没有
对于3,我想知道错误
那么如何使用expect
或Pexpect
做到这一点?最好Pexpect
谢谢!