1

I've created a small Bash script that does a MySQL data dump. Because the dump can be fairly large I put the process in the background and then wait for either an error or the log to show up in the file system. I have the following code:

mysqldump main_db > /loc/to/dmp/file.sql 2>/loc/to/error/log/file.log &

The problem is that I get a '/loc/to/error/log/file.log' file the size of 0 (which I presume means no real error) sometimes when this command is run, which kills the process, even though there is no error.

I'm not sure why the STDERR would write a file when there was no data to write. Is this because of the & background process?

4

3 に答える 3

5

リダイレクトされたファイルは、実行中のシェルによってスクリプトが実行される前に設定されます。

つまり、リダイレクトされた stdout/stderr を含むコマンドを解析した後、シェルはフォークして開きます (ファイルが存在しない場合は作成します)。開いているファイル記述子をファイル記述子 1 および 2 (それぞれ stdout/err) にアタッチしてから、実際のコマンドを実行します。

于 2009-08-10T18:08:38.493 に答える
0

リダイレクトファイルは、データが書き込まれたかどうかに関係なく作成されます。エラーログを監視しているプロセスは、存在ではなく、ゼロ以外のファイルサイズをチェックする必要があります。

于 2009-08-10T18:10:28.643 に答える