sc_ray
sc_ray

Reputation: 8043

Passing arguments to a shell script to be executed within ssh

I am trying to write a deployment script that will take the command I need to run on the remote machine and then run it on the remote machine. What I am envisioning is something as follows:

./DeployAndRunScript.sh "java -jar runmyjar.jar -t args &"

In my DeployAndRunScript.sh, the very last line is:

ssh -i $pemfile $targetmachine "java -jar $runcommandhere"

I was wondering, what would be a way to get the arguments from the commandline into the "runcommandline" alias and execute it within the script?

Upvotes: 0

Views: 202

Answers (1)

pdexter
pdexter

Reputation: 811

To get the arguments in a shell script you can type $@. Taking that a step further, you can simply change the last line to

ssh -i $pemfile $targetmachine "$@"

(edit: added quotes around $@, nice catch Barmar!)

You could replace $@ with $1 if you know that the command will be the first argument wrapped in quotes.

Upvotes: 2

Related Questions