3

SCP を使用するときに out と err の両方をリダイレクトする方法、または stdout 自体をリダイレクトする方法については多くの話がありますが、stdout が引き続き画面に出力されている間に stderr をファイルにリダイレクトする方法を誰かが知っているかどうか知りたいです。

現在、次のように stderr をリダイレクトすると:

scp user@XXXX:*.txt  . 2>errfile.txt

stdout には何も表示されず、エラーとエコーのみが errfile.txt に取り込まれます。

4

1 に答える 1

0

これがどのように機能するかです

MPBAB:work anj$ cat test.sh
echo "Hello there"
echo "This is a test script"

badcommand
MPBAB:work anj$ ./test.sh 2> err.log
Hello there
This is a test script
MPBAB:work anj$ cat err.log
./test.sh: line 4: badcommand: command not found

ご覧のとおり、test.sh呼び出そうとするとbadcommandエラーがスローされます。ただし、2 つのechoステートメントは問題なく機能し、 に表示されSTDOUTSTDERRは にログインしerr.logます。

今あなたが試した方法を実装しています-

MPBAB:work anj$ ./test.sh . 2>err.log
Hello there
This is a test script
MPBAB:work anj$ cat err.log
./test.sh: line 4: badcommand: command not found

同じように動作します。あなたの場合、scpあなたが発行しているコマンドは正しくないと考えざるを得ません。とscpが必要です。このようなもの( test.txtをリモートサーバーに送信したい場所)sourcedestinationscp

MPBAB:work anj$ scp ./test.txt user@secure.server.com:/home/data 2>scperr.txt
user@secure.server.com's password: #<this is because I dont have the public key installed>
test.txt              100%  291     0.3KB/s   00:00    
MPBAB:work an$ cat scperr.txt
MPBAB:work anj$ 

ご覧のとおり、ファイルがコピーされ、test.txt 100% 291 0.3KB/s 00:00エラーSTDOUTがなかったためscperr.txt空でした。

于 2012-08-09T03:41:21.293 に答える