经过一番研究:
我想出了一个脚本,可以登录到远程服务器,然后登录到 telnet 服务器(从远程服务器):
脚本文件
cat run_on_remote.sh | sshpass -p "$PASS" ssh -t -t -o StrictHostKeyChecking=no host@serv
run_on_remote.sh:
echo "[REMOTE] Logged into remote. Current working directory `pwd`"
echo "[REMOTE] Moving deployment to /some/dir"
mv "deployment.rar" "/some/dir"
(
echo open "localhost 50008"
sleep 2
echo "user"
sleep 2
echo "pass"
sleep 2
echo "ls -la | grep deployment-name"
sleep 2
echo "undeploy deployment-name"
sleep 5
echo "deploy deployment-name"
sleep 5
echo "Redeployed adapter"
echo "exit"
) | telnet
echo "Finishing SSH session"
exit
但我收到以下错误:
) | telnet
Too many )'s.
如果我将脚本上传到远程服务器,它就会按预期工作。为什么?