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
3 Answers
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
zilcuanu
Then it is synchronous right.
Arkadiusz Drabczyk
Sorry, I don't understand - is it a question?
ceving
@Pradeep everything without a
& at the end is synchronous.zilcuanu
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.
Arkadiusz Drabczyk
That's correct. Just add
& after the COMMAND to make it asynchronous |
sshin 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.