2011-09-13 70 views
8

我要确保每次有人登录到我的服务器我收到一封电子邮件,说:发送电子邮件的ssh登录

ALERT壳牌访问:周二6月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`" [email protected] 

.bashrc

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

感谢你的帮助,J当bash运行一个交互式非登录shell,如果您连这是不是这样执行

+0

你是否通过'source〜/ .bashrc'重新加载〜/ .bashrc?你是否尝试注销并重新登录? – ajreal

+0

你在/ var/log/messages或类似的东西中收到任何消息吗?该用户/环境是否知道邮件的位置? – CtrlDot

+0

是的,我完全注销,并重新登录。我也试过source〜/ .bashrc,但没有成功 – Tech4Wilco

回答

11

的.bashrc。 添加相同的代码中的.bash_profile应运行时,外壳是登录shell

注:从.bash_profile中许多发行源的.bashrc,我可能是错误的,这个问题可能不是约的.bashrc/.bash_profile中

+0

它的作品,但我失去了我所有的颜色主题等...当我删除.bash_profile一切都恢复正常 – Tech4Wilco

+0

你是什么发行版使用 ? – Sorin

+0

对于Ubuntu,一个Linux CentOS 5和一个Ubuntu Server 10.04 – Tech4Wilco