0

更新されている場合は、wgetを使用して、サーバーの1つから1時間に1回ファイルを取得しています。wgetが更新されたファイルをダウンロードするときに、スクリプトで従業員に電子メールを送信したいと思います。

wgetがファイルを取得しない場合、テキストwget出力の最後のビットは次のようになります。

file.exe' -- not retrieving.
<blank line>

そのテキストを監視し、そのテキストが表示されない場合にのみメールコマンドを実行するにはどうすればよいですか?

4

3 に答える 3

7

私は次のようなものでそれをします

if ! wget ... 2>&1 | grep -q "not retrieving"; then
   # run mail command
fi
于 2009-12-31T22:57:15.617 に答える
3

wget成功したときと失敗したときの''の終了ステータスは何ですか?ほとんどの場合、ゼロ以外の終了ステータスで障害が報告されます。この場合、ほとんどの場合、些細なことです。

if wget http://example.com/remote/file ...
then mailx -s "File arrived at $(date)" victim@example.com < /dev/null
else mailx -s "File did not arrive at $(date)" other@example.com < /dev/null
fi

''からの出力を分析する必要がある場合は、wgetそれをキャプチャして分析します。

wget http://example.com/remote/file ... >wget.log 2>&1
x=$(tail -2 wget.log | sed 's/.*file.exe/file.exe/')

if [ "$x" = "file.exe' -- not retrieving." ]
then mailx -s "File did not arrive at $(date)" other@example.com < /dev/null
else mailx -s "File arrived at $(date)" victim@example.com < /dev/null
fi

ただし、この場合、他のメッセージが原因で他のエラーが発生し、それが不正確なメール送信につながる可能性があることを心配しています。

于 2009-12-31T23:02:41.517 に答える
0
if ${WGET_COMMAND_AND_ARGUMENTS} | tail -n 2 | grep -q "not retrieving." ; then
    echo "damn!" | mail -s "bad thing happened" user@example.com
fi
于 2009-12-31T22:55:39.083 に答える