@ysongzybl
2015-05-01T21:25:24.000000Z
字数 963
阅读 1179
bash
I want to run a script test.sh on local host
and the test.sh access server "eos" via SSH, on the background.
The test.sh contains :
#!/bin/bash
ssh eos 'sh -c "(echo "hello" > yang.txt"'
Solution:
Use nohup
command on local machine:
nohup ./test.sh &
Result:
In the yang.txt file on server eos, there is one word "hello".
The test.sh takes one parameter :
#!/bin/bash
ssh eos " echo $1 >> yang.txt"
Solution:
Use nohup
command on local machine:
nohup ./test.sh "song" &
Result:
In the yang.txt file on server eos, there is one word "song".
Explanation [2]:
Variables in single-quotes are not evaluated. Use double quotes:
ssh pvt@192.168.1.133 "~/tools/run_pvt.pl $BUILD_NUMBER"
The shell will expand variables in double-quotes, but not in single-quotes.
This will change into your desired string before being passed to the ssh command.
[2] http://stackoverflow.com/questions/3314660/passing-variables-in-remote-ssh-command