2017-10-17 46 views
0

我試圖設置一個簡單的單行搜索以查看文件是否存在,如果存在,請通過電子郵件通知我。發送電子郵件如果文件名存在

這是我使用搜索的命令:

find . -name "error_log" 

基本上,我只是想用sendmail或類似的東西,如果產生一個error_log文件來拍我的電子郵件。不需要是任何幻想,只是一個簡單的消息,如「文件存在」。

有沒有簡單的方法來做到這一點?

+1

發現的一部分。 -iname'filename'-exec sendmail'做些什麼。在谷歌搜索找到執行和人總是你的朋友(人發現) –

回答

0

你可以試試這個:

#!/bin/bash 

rm /tmp/log 
find . -name "error_log" > /tmp/log 
[[ -s /tmp/log ]] && mail -s 'error logs' [email protected] < /tmp/log 
+0

是不是限制搜索到'/ tmp/log'?我有在各種目錄中創建的error_log文件... – James

+0

我發現了幾個像這樣的教程,但他們都沒有顯示如何搜索所有目錄:https://www.cyberciti.biz/tips/find-out- if-file-exists-with-conditional-expressions.html – James

+0

/tmp/log只是爲您的需要而創建的文件... –

0
find . -name "error_log" | ifne mail -s 'error logs' [email protected] 

ifne是moreutils(Debian的)

相關問題