Reputation: 407
I'm trying to pass along variables via ssh, and wrote two short testscripts (bash)
This one is to the execute the script on the other side (and it works, at least partially)
I start it with executing: 'mms test alpha one'
#!/bin/bash
sshpass -p (password) ssh [email protected] 'bash /scripts/mms2 "$@"'
The second script that are executed is:
#!/bin/bash
echo "$@" >/scripts/test1.txt
This script is only for testing if the parameters are are transfered.
So far it creates the text file, but it's empty, so I have no idea if there's wrong with both or only one of the script.
Basically I want to pass a set of variables to the script on the server, these variables can contain spaces.
Anybody have any tips?
Upvotes: 0
Views: 38
Reputation: 407
I found out by @Gordon Davidsson comment that the $(printf "%q " "$@")
could be used to send it as a string, so the remote server didn't interpret the variables as different commands.
My new and working script is:
#!/bin/bash
sshpass -p (password) ssh [email protected] "bash /scripts/mms2 $(printf "%q " "$@")"
Upvotes: 1