[HowTo] Receive an eMail during a SSH login - Printable Version +- ispCP - Board - Support (http://www.isp-control.net/forum) +-- Forum: ispCP Omega Contributions Area (/forum-40.html) +--- Forum: Howtos (/forum-41.html) +--- Thread: [HowTo] Receive an eMail during a SSH login (/thread-11025.html) |
[HowTo] Receive an eMail during a SSH login - BeNe - 06-21-2010 05:41 PM This is only a one line code, but sometimes very helpful and interesting. You will recieve an eMail from the Server in seconds if someone login via SSH. A not invited guest has no more chance Just add this line under Debian to your "/etc/bash.bashrc" Code: # Generate e-Mail on Login I´m sure this works also on other Linux distributions if you know the correct systemwide "bashrc" Greez BeNe RE: [HowTo] Receive an eMail during a SSH login - c0urier - 06-22-2010 02:15 AM Nice one BeNe, never thought about that tbh =) Thumbs up. RE: [HowTo] Receive an eMail during a SSH login - c0urier - 06-29-2010 10:04 AM @ BeNe, I think you've added a ` to much. Code: # Generate e-Mail on Login Shouldn't it be: Code: # Generate e-Mail on Login RE: [HowTo] Receive an eMail during a SSH login - schnere - 08-04-2010 06:51 PM @c0urier: It should be Code: echo 'Login on' `hostname` `date` `who`| mail -s "Login on `hostname` `who | awk '{print $5}'`" YOUR@E-MAILADRESS.TLD You may add it to /etc/profile because /etc/bash.bashrc only gets executed on starting a root shell, but /etc/profile gets executed on every user login. RE: [HowTo] Receive an eMail during a SSH login - c0urier - 08-04-2010 08:25 PM (08-04-2010 06:51 PM)schnere Wrote: @c0urier: It should be Well the way I posted it, it works in my /etc/bash.bashrc - But only when I removed the extra signs =). RE: [HowTo] Receive an eMail during a SSH login - schnere - 08-04-2010 09:16 PM (08-04-2010 08:25 PM)c0urier Wrote: Well the way I posted it, it works in my /etc/bash.bashrc - But only when I removed the extra signs =). Yes, it works, but not how it should work, because who | awk '{print $5}' is a shell command which only gets executed within ` signs. With your variant you will receive emails with "who | awk '{print }'" in subject instead of the ip address. And yes, it works in /etc/bash.bashrc , but for me in Debian Lenny /etc/bash.bashrc only gets executed on root login. Because I want to see every user login, my solution is to use /etc/profile . Just wanted to share my thoughts. Regards, schnere RE: [HowTo] Receive an eMail during a SSH login - c0urier - 08-05-2010 12:40 AM @schnere If I don't remove the extra ` that is added in BeNe's example I get errors. I'm sure that extra ` should not be there. This works for me: WRONG: Code: echo 'Login on' `hostname` `date` `who`| mail -s "Login on `hostname` who | awk '{print $5}'" YOUR@E-MAILADRESS.TLD And not: WRONG: Code: echo 'Login on' `hostname` `date` `who`| mail -s "Login on `hostname` `who | awk '{print $5}'`" YOUR@E-MAILADRESS.TLD I've added it in the profiles and correct you receive a mail at every login now, but not with the second example it just generates an error. Tested on Debian Lenny, Debian Squeeze and CentOS 5.0. And you are right, it has a better effect in /etc/profile - Thanks for that! ***************** @ schnere Nr2: =) I can see you added an extra ` which is not added in BeNe's suggestion, so the correct is as you write. Correct: Code: echo 'Login on' `hostname` `date` `who`| mail -s "Login on `hostname` `who | awk '{print $5}'`" YOUR@E-MAILADRESS.TLD RE: [HowTo] Receive an eMail during a SSH login - Knut - 08-05-2010 04:59 AM Thank you BeNe |