これがどのように機能するかです
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ステートメントは問題なく機能し、 に表示されSTDOUT、STDERRは にログインし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空でした。