After some research:
Script to ssh and run a command doesn't work
Make a shell script execute commands in telnet or programs
I've come up with a script that logs into a remote server and then into a telnet server (from the remote server):
script.sh
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
but I get the following error:
) | telnet
Too many )'s.
If I upload the script to the remote server it works as intended. Why?