简体   繁体   中英

Pass along variables via ssh

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 hellfire@192.168.0.11 '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?

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 hellfire@192.168.0.11 "bash /scripts/mms2 $(printf "%q " "$@")"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM