我不确定我现在是否有能力对此进行测试,但想知道是否有人可以建议是否可以做这样的事情:
Run a shell script
Shell Script SSH's into a machine (Connection requires SSH key only)
Stuff is run on that machine
Script run on that machine SSH's into another machine (Connection requires SSH key and password)
Stuff is run in that machine
Exit from that machine
Stuff is run in that machine
Exit from that machine
More stuff happens for a few hours
Run Code Online (Sandbox Code Playgroud)
想必这只是组装所需级别的脚本并让它运行的情况?借用另一个 SoF 问题的例子:
sshScript='
ls -la
sshScript2=`
ls -la
`
ssh -t ${UserName}@server "${sshScript2}"
ls -la
'
ssh -t ${UserName}@server "${sshScript}"
Run Code Online (Sandbox Code Playgroud)
在 sudo 的情况下我只是运行sudo -s -u user bash -c script
什么?
我只是不确定这是否会导致无限循环,并且由于我连接的机器处于生产环境中,我无法承担出于测试目的而破坏它们的风险。
在这种情况下,我通常使用heredoc将脚本提供给远程shell。但是,当脚本需要来自标准输入的用户输入时不可用。
ssh ${UserName}@server <<EOF1
ls -la
ssh ${UserName}@server <<EOF2
ls -la
EOF2
ls -la
EOF1
Run Code Online (Sandbox Code Playgroud)