我想确保每次有人登录我的服务器时,我都会收到一封电子邮件,上面写着:
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
最佳答案
.bashrc 在 bash 作为交互式非登录 shell 运行时执行,而在 ssh 时则不是这样。 在 .bash_profile 中添加相同的代码,当 shell 是登录 shell 时应该运行该代码
注意:许多发行版的 .bashrc 来自 .bash_profile,我可能错了,问题可能与 .bashrc/.bash_profile 无关
关于bash - 通过 ssh 登录发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7405406/