Nested ssh startup commands on 2nd server

I can only get hostB from hostA and I want to run commands on hostB.

ssh -t $hostA ssh -t $hostB "

   echo 'Hello World!'

   echo 'Test!'

"

      

At the moment it will connect to hostA, then hostB and the script will be paused. As soon as I type exit (from hostB), I go back to hostA, 2 echo commands are printed and then automatically exit hostA.

How can I run commands on hostB?

+3


source to share


1 answer


Modifying the code using the doc here and sshpass

might do the trick



ssh -T user@$hostA <<EOA
sshpass -p password ssh  -T user@$hostB <<EOB
echo hello 
EOB
EOA

      

+1


source







All Articles