4

I have a deployment script located on a build server. Each time I need to generate the build I need to login to the server using ssh and then trigger the deployment script. I managed to generate the public/private keys so that I need not enter the password to login to the build server. But still I need to login and run the deployment script. Is there a way where to automate the login, executing the deployment script on the build server and then exit from in one local script. How to achieve this

2
  • Well, you can certainly execute a call to ssh in a local script and hand over code or a remote file to be executed remotely. That is well documented and you can find endless examples for that on the internet. Commented Apr 28, 2017 at 14:50
  • Did some1 answer your question, or do you want to automate the login too ? If so what are those criteria (like time or event)? Commented Apr 28, 2017 at 15:22

3 Answers 3

2

You can use a pipe (assuming you are using a *nix OS):

echo "your --command --here" | ssh user@host
Sign up to request clarification or add additional context in comments.

Comments

0

Usually it's just

ssh buildserver /path/to/build.sh

You may need to tweak the options though.

Comments

0

Just do ssh <HOST> <COMMAND> in a single line. If you can already log in using keys you won't have to type a password. Example:

$ ssh localhost 'echo hi'
hi

This <COMMAND> is run synchronously. That means that ssh won't finish until <COMMAND> run on the remote server has finished. See yourself:

$ ssh localhost 'sleep 10'

This command will wait for 10 seconds and you won't be able to type new commands until it's finished.

7 Comments

Then it is synchronous right.
Sorry, I don't understand - is it a question?
@Pradeep everything without a & at the end is synchronous.
You have mentioned it is asynchronous in your answer. I think it is synchronous since you will not be able to run any commands till the command on the remote server is finished.
That's correct. Just add & after the COMMAND to make it asynchronous
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.