【问题标题】:Setting up a 'find' command cron/bash script, which emails if there are any results?设置“查找”命令 cron/bash 脚本,如果有任何结果,会发送哪些电子邮件?
【发布时间】:2011-02-12 17:21:22
【问题描述】:

我想设置一个 cron 作业来检查例如每 24 小时查看如下“查找”命令(检查恶意 shell 黑客脚本)是否有任何结果:

find /home/username/public_html -type f -print0 | xargs -0 egrep '(\/tmp\/cmd(temp)?|SnIpEr_SA|(c99|r57|php)shell|milw0rm)'

如果有任何结果,那么我会在指定的电子邮件地址(例如exam@ple.com)收到一封电子邮件。

也许每天运行一次调用 bash 脚本的 cron 作业,其中 find 命令通过 bash 脚本运行,bash 脚本检查 find 命令返回的字符数,并在以下情况下发送电子邮件大于 0。不确定这是否是最好的方法,但这是我能想到的唯一方法。

我不知道足够的 bash 编程来实现它(或任何类似的替代方案) - 这个实现是什么样的?

【问题讨论】:

    标签: linux bash find cron


    【解决方案1】:

    cron 的默认操作是在您的脚本有输出时向您发送电子邮件 只需编辑您的 crontab (crontab -e) 并在顶部添加 MAILTO 变量。

    MAILTO=exam@ple.com
    30 1 * * * find /home/username/public_html -type f -print0 | xargs -0 egrep '(\/tmp\/cmd(temp)?|SnIpEr_SA|(c99|r57|php)shell|milw0rm)'
    

    【讨论】:

    • 感谢上帝,有人给出了这个答案,我期待一个 && 或 ||回答。
    • 谢谢 :) 有没有办法将 MAILTO 应用于单个 cron 行,而不是整个选项卡?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    • 2018-01-15
    • 2012-12-24
    相关资源
    最近更新 更多