Multiple remote SSH commands

Hi there,

I am trying to figure out how to write down multiple SSH commands on the remote server. For now I created environment variables to make it less painfull to do a ssh login per command, but I prefer to open one SSH connection and then execute all the commands (more efficient).

My only working solution now is to create separate lines with SSH login and commands:

 - ssh $DEPLOY_USER@$DEPLOY_SERVER tar -xzf $DEPLOY_PATH/deployarchive.tar.gz --directory="$DEPLOY_PATH/folder" 
- ssh $DEPLOY_USER@$DEPLOY_SERVER wget --cache=off --output-document $DEPLOY_PATH/deploy.sh https://a-file-on-the-internet.sh
etc etc
 
I tried some varations (see below), but that leads to build failures as the SSH command is not working (interpreted as one string or command not remotely executed but on docker image)
 
Variation 1
- ssh $DEPLOY_USER@$DEPLOY_SERVER 'tar -xzf $DEPLOY_PATH/deployarchive.tar.gz --directory="$DEPLOY_PATH/folder"; wget --cache=off --output-document $DEPLOY_PATH/deploy.sh https://a-file-on-the-internet.sh;'
Variation 2
 - ssh $DEPLOY_USER@$DEPLOY_SERVER << EOF
              tar -xzf $DEPLOY_PATH/deploy.tar.gz --directory="$DEPLOY_PATH/folder";
              wget --cache=off --output-document $DEPLOY_PATH/deploy.sh https://a-file-on-the-internet.sh;
            EOF;
As I use ENV variables for most commands, I was not able to find a way to include those variables in the remote bash script, otherwise I had to execute only one bashscript to do all the tasks. And besides, when you put multiple commands in 1 bash script, you don't have the advantage of the step by step logging in bitbucket pipelines, as it is interpreted as 1 command.
 
Hope anyone has a solution!
 
Peter
 

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,196 views 8 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you