我想用 grep 拖尾日志文件并通过邮件发送
喜欢:
tail -f /var/log/foo.log | grep error | mail -s subject name@example.com
我怎样才能做到这一点?
最佳答案
您想在发生电子邮件错误时发送电子邮件吗?那可能会失败;)
但是,您可以尝试以下操作:
tail -f $log |
grep --line-buffered error |
while read line
do
echo "$line" | mail -s subject "$email"
done
为 grep 输出中的每一行发送一封电子邮件。
使用上面的 shell 脚本运行
nohup ./monitor.sh &
所以它会一直在后台运行。
关于email - tail 和 grep 日志和邮件 (linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4656886/