5

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!

3 Answers 3

6

Just pass the command as an argument to ssh.

ssh someserver /path/to/some/script.bsh
Sign up to request clarification or add additional context in comments.

2 Comments

Im not trying to do this via command line but as a script, there will be no manual typing to trigger the script.
This does not require manual typing if the RSA key pair is set up in advance.
1

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

Comments

0

Another way, using expect package.

Disclaimer: This you can use for testing environments since it has an open password. but depends on your usecase

If your server does not have expect, you may add the package then. run the command. You can also put this command inside an .sh script.

expect -c 'spawn ssh [email protected] "/path/to/my.sh"; expect "assword:"; send "Y0urp@ssw0rd\r"; interact'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.