2012-10-01 49 views
0

我想要一個cron作業每天掃描日誌並通過電子郵件報告所有錯誤行。我可以處理PHP,但我是Unix新手。有沒有可以將輸出寫入另一個文件的快速Unix命令,我可以使用其他作業發送電子郵件?掃描日誌查找錯誤和電子郵件錯誤行

回答

0

當然,

你要重定向輸出和錯誤的文件...

請看下面的crontab的例子!

* * * * * root script.php 2>&1 /tmp/script-output.log | mail -s 'Subject' [email protected] 

Byeee!

+0

或者你應該看看php函數:set_error_handler和mail。 – Rodrigo

+0

這是一個可行的解決方案嗎? 1)在web根目錄下創建一個「auto_prepend.php」文件並添加: <?php register_shutdown_function('error_alert'); 功能error_alert() { 如果(is_null($ E = error_get_last())===假) { 郵件('[email protected]」, '從的auto_prepend',的print_r錯誤($Ë ,true)); } } ?> 2)然後將這個「php_value auto_prepend_file /www/auto_prepend.php」添加到Web根目錄中的.htaccess文件中。 ---來自:php.net/manual/en/function.set-error-handler.php – Prasad

+0

由於這是一個共享主機的網絡應用程序,我可能沒有訪問ROOT ..它會工作沒有?什麼是script.php在做什麼? – Prasad