vsingal5
vsingal5

Reputation: 304

Passing multiline arguments to ssh in bash?

I want to pass the following arguments to the bash script:

ssh -t $slaveAddr "chmod a+rwx newSlaveInstallation.sh; 
echo 'running the installation script....';
./newSlaveInstallation.sh $USERNAME $NEW_REPLICATION_VAL "$slaveList"; 
exit"

username is a username like "user", new replication val is a number, and slavelist is a list of new line separated list of IP addresses like "1.2.3.4 derp\n 1.2.3.5 derpp" However, once I pass these three parameters into ssh, for slaveList, it only takes into consideration the IP address and not the entire string of new line separated values. In other words, if within the script, I echo slaveList, it gives me "1.2.3.4" Is there any special formatting to pass in the entire value of the string? Thanks!

Upvotes: 1

Views: 2376

Answers (1)

iamauser
iamauser

Reputation: 11479

You need to escape the double-quotes inside the first and last ones. Otherwise the command will be truncated.

ssh -t "$slaveAddr" "chmod a+rwx newSlaveInstallation.sh; 
echo 'running the installation script....';
./newSlaveInstallation.sh $USERNAME $NEW_REPLICATION_VAL \"$slaveList\"; 
exit"

Upvotes: 4

Related Questions