Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run shell script in another server in a script?

No where online can i find a way to run a shell script on a remote server from another script. This is for automation, so the script on the host machine will automatically trigger another script on a different server. The server that my script will ssh to will either have a password prompt or have RSA key pair set up

Thanks!

like image 797
Shengqi Wang Avatar asked Jun 06 '16 21:06

Shengqi Wang


People also ask

How do I run a shell script from anywhere?

In order to run a Bash script from anywhere on your system, you need to add your script to your PATH environment variable. Now that the path to the script is added to PATH, you can call it from where you want on your system. $ script This is the output from script!

How do I run a script on a remote server?

To run a script on one or many remote computers, use the FilePath parameter of the Invoke-Command cmdlet. The script must be on or accessible to your local computer. The results are returned to your local computer.


2 Answers

Just pass the command as an argument to ssh.

ssh someserver /path/to/some/script.bsh
like image 87
Quentin Avatar answered Sep 23 '22 19:09

Quentin


Let's say you want to execute a script on node2 but you have your script on node1 file name of script is sp over location /home/user/sp. Simply

ssh node2 < /path-of-the-script-including-the-filename
like image 31
user12711146 Avatar answered Sep 23 '22 19:09

user12711146