2019年3月14日 星期四

Bash Tip - Run Command with multiple arguments with ssh




This is a note for logging my simple way to use ssh and bash with continuous integration on remote server.

You can execute the following test-cases.sh on your host.

It will execute remote script of the test with correct argument contents.

source code of test-cases.sh on host





directory layout of tester account on test-server



source code of tests.sh on test-server




result of test-cases.sh example

source ./test-cases.sh
➜  ~ run_cases "\"1\"\"" "b'\"" "c'#\"" "\"\"" "\'"
ssh test-server cd test-cases; /bin/bash ./tests.sh  "\"1\"\"" "b\'\"" "c\'\#\"" "\"\"" "\\'"
argv[1]=["1""]
argv[2]=[b\'"]
argv[3]=[c\'\#"]
argv[4]=[""]
argv[5]=[\\']

Notes

printf %q  is use to make safe quote the argument if hashtag(#), quote('), double quote(") and so on.

Appendix



沒有留言: