-1

I want to run a script a.sh that will do the following steps -

  1. Run few commands
  2. Call another shell script b.sh in the same server - server01
  3. b.sh will login to another server - server02 and run the commands that follow.

I am able to do till step 2 correctly. In step 3, I am able to loin to another server but it stops there. It does not run the steps that follow.

Have a look at the two scripts.

a.sh

cd ~/sample/home && python helloworld.py
#!/bin/bash
cd ~/sample/ && ./b.sh

b.sh

ssh username@server02.com
echo "In server02"

Both a.sh and b.sh are in the same server, that is server01.com. Here, I want a.sh to run in server01 and then b.sh to run in server01. Once b.sh runs, it should do ssh to server02 and print "In server02".

I am able to do till ssh to server02. After that it is not printing "In server02" in server02.

Is there a way to do it?

TeeKay
  • 777
  • 1
  • 11
  • 46

1 Answers1

0

Use a heredoc.

ssh username@server02.com << EOF
  echo "In server02"
EOF
JShorthouse
  • 706
  • 6
  • 23
  • In [How to Answer](https://stackoverflow.com/help/how-to-answer), note the section "Answer Well-Asked Questions", and therein the bullet point regarding questions which "have been asked and answered many times before". – Charles Duffy Jul 31 '19 at 15:15