Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a remote bash script with arguments from local

I'm new to shell scripting and having a little trouble.

I'm trying to execute a remote script from local machine. The script on local machine is passed four arguments, and it executes the following line:

ssh $STACK 'bash -l -c "./deploy_intermediate.sh $2 $3 $4"'

However, I cannot get $2, $3, and $4 to put out the passed arguments. Is there any way to be able to access them within single quotes? What is the best way of executing the above line.

I would really appreciate any help.

thanks.

like image 926
user1801879 Avatar asked Mar 18 '23 15:03

user1801879


2 Answers

The trick is:

ssh -i ~/.ssh/"$GIT_PRIVKEY" user@"$IP" "bash -s" < localpath/script.sh "$arg1" "$arg2"
like image 131
muratgozel Avatar answered Mar 20 '23 05:03

muratgozel


To pass the parameters you'd have to write:

ssh $STACK 'bash -l -c "./deploy_intermediate.sh '$2 $3 $4'"'

Thus you make way for the $i values to be expanded. Yet, I think you'd probably be able to get the same result by simply running:

ssh $STACK "./deploy_intermediate.sh $2 $3 $4"
like image 24
Rubens Avatar answered Mar 20 '23 05:03

Rubens