0

After some research:

Script to ssh and run a command doesn't work

Multiple commands in sshpass

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?

Sebi
  • 999
  • 5
  • 16
  • 29
  • 2
    Perhaps consider using `expect` to interact with `telnet`. (It was designed for automating this kind of interaction, and it's fabulous software.) To start, use `autoexpect` to write the script for you initially, and then clean up the generated script a bit if needed or desired afterward. – Christopher Aug 16 '19 at 16:55
  • 1
    This might help: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Aug 16 '19 at 17:12
  • 1
    You've tagged this `bash` - but `Too many )'s` sounds like something `tcsh` would say - you may want to check host@server's login shell – steeldriver Aug 16 '19 at 17:40

0 Answers0