【问题标题】:Send Email If Filename Exists如果文件名存在则发送电子邮件
【发布时间】:2018-03-29 08:41:45
【问题描述】:

我正在尝试设置一个简单的单行来搜索以查看文件是否存在,如果存在,请通过电子邮件通知我。

这是我用来搜索的命令:

find . -name "error_log"

基本上,如果生成了error_log 文件,我只想使用sendmail 或类似的东西向我发送电子邮件。不需要什么花哨的东西,只是一个简单的消息,比如“文件存在”。

有什么简单的方法吗?

【问题讨论】:

  • 找到 . -iname '文件名' -exec sendmail '做点什么。在谷歌上搜索 find exec,man 永远是你的朋友(man find)

标签: linux bash shell command-line command


【解决方案1】:

你可以试试这个:

#!/bin/bash

rm /tmp/log
find . -name "error_log" > /tmp/log
[[ -s /tmp/log ]] && mail -s 'error logs' you@domain.tld < /tmp/log

【讨论】:

  • 不是限制搜索到/tmp/log吗?我在各个目录中创建了 error_log 文件...
  • 我找到了几个这样的教程,但似乎没有一个显示如何搜索所有目录:cyberciti.biz/tips/…
【解决方案2】:
find . -name "error_log" | ifne mail -s 'error logs' you@domain.tld

ifne 是 moreutils (debian) 的一部分

【讨论】:

    猜你喜欢
    • 2011-08-09
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 2015-08-10
    • 2017-01-16
    • 1970-01-01
    相关资源
    最近更新 更多