【问题标题】:Find & Replace via ssh - send a result via mail通过 ssh 查找和替换 - 通过邮件发送结果
【发布时间】:2013-07-17 20:27:38
【问题描述】:

我遇到了一个小问题,我每 5 分钟运行一次 cron 任务,它正在查看文本链并将其替换为任何内容.. 为了优化某些东西,我想在我的 cronstrask 中添加一个新功能:如果它替换了某些东西,请给我发一封电子邮件。如果 crontask 没有找到链,则无需发送邮件。我不知道该怎么做,也许你可以帮助我。 这是我当前的 cron 任务:

find /home -type f | xargs sed -i 's$chain if would like to era$ $g'

提前致谢

【问题讨论】:

    标签: email replace cron


    【解决方案1】:

    这是我在其他人的帮助下做的一个例子。 它可能会帮助其他一些人

    #!/bin/bash
    grep -r -q 'stringtoreplace' /home/     #Find the string in all files on my home
    if [ $? == 0 ] #if the  last result fit  then
    then
            echo "At the following time : " $(date +%H:%M:%S) | mail -s "[Serveur Leaked] Bad iframe has been found " my@mail #we send a mail with the date
            find /home -type f | xargs sed -i 's$stringtoreplace$ $g' #we replace the string with a whitespace
    else
            exit 1
    fi
    exit 0
    

    【讨论】:

      最近更新 更多