bash – 在ssh登录时发送电子邮件

前端之家收集整理的这篇文章主要介绍了bash – 在ssh登录时发送电子邮件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想确保每次有人登录我的服务器时都收到一封电子邮件说:

ALERT Shell Access on: Tue Jun 16 11:04:10 CDT 2009 user123 pts/0
2009-06-16 11:04

所以我把这段代码

echo 'ALERT Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | cut -d"(" -f2 | cut -d")" -f1`" example@example.com

在.bashrc中.

为什么我没有收到任何电子邮件

谢谢你的帮助,J

当bash作为交互式非登录shell运行时执行.bashrc,而不是ssh时的情况.
在.bash_profile中添加相同的代码,该代码应该在shell是登录shell时运行

注意:许多发行版从.bash_profile中获取.bashrc,我可能错了,问题可能不是关于.bashrc / .bash_profile

原文链接:https://www.f2er.com/bash/385029.html

猜你在找的Bash相关文章