Monday, January 26, 2009

How to get an email when someone logs into a shell account

Add the following 2 lines at the bottom of the .bashrc file. Replace YOURUSERNAME with the shell login and replace YOUR@EMAIL.ADDRESS with a valid email address:


echo "Today is $(date) User is: `who | grep YOURUSERNAME | awk '{ print $6 }'`" > ~/lastuser.txt

mail -s 'user YOURUSERNAME logged into server XYZ' YOUR@EMAIL.ADDRESS < ~/lastuser.txt

No comments:

Post a Comment