0

I have an scp script that looks like this:

#!/bin/bash
scp -r /usr/local/htdocs/$1 httpd@$2:/local/htdocs

I want to call it from the command line, and pass a directory, and destination server, similar to this:

move_site.sh website  servername

However, I want to capture the output in a file containing the 2 parameters.

So I tried this, but it didn't print anything when calling using nohup

#!/bin/bash
scp -r /usr/local/htdocs/$1 httpd@$2:/local/htdocs > $1$1.out

How can I structure both the script and the calling command so that it runs in the background, and captures the output based on destination and site?

4

2 に答える 2

0

2 つ以上の単語を 1 つのパラメーターとして渡したい場合は、引用符で囲む必要があります。

$ cat s.sh 
#!/bin/bash
echo "param1: $1, param2: $2"

したがって、次のようになります。

$ ./s.sh "a b" c
param1: a b, param2: c

この例に従って、結果としてスクリプトを調整する必要があります。

于 2013-02-13T14:46:41.647 に答える
0

スクリプトは機能するはずですが、scpの試行中にエラーが発生した可能性があります。そのため、出力ファイルは空ですか? エラー メッセージを出力ファイルにもキャプチャするには、次のように変更>>&ます。

#!/bin/bash
scp -r /usr/local/htdocs/$1 httpd@$2:/local/htdocs >& $1$2.out

スクリプトをバックグラウンドで実行するに&は、コマンドの最後に次のように追加します。

move_site.sh website  servername &

PS Web サイトサーバー名には、ファイル名に使用できない文字を含めないでください$1$2.out

于 2013-02-13T15:00:29.720 に答える