Logoff Notification
Hello, I am newbie to Linux, my requirement is I want to send a notification when any user login or logout of the system in text mode. I don't want to call the notification script in user home .bash_profile and .bash_logout because in that case user can modify these files and then my notification script fails to send any notification from next time.
Through one of the post in the forum I found that putting notification script in /etc/profile, we can invoke notification script at logon but still I am unable to find anyway for logoff event in the same way. Please help... :) |
You could, of course, just make the files ~/.bash_login and ~/.bash_logout
owned by root in the users home, and the perms 0644 ... Cheers, Tink |
Thanx Tinkster for your quick reply.
But in that case normal user would be unable to add his own environment variables or anything he wants to do with that. I just don't want user to restrict from any rights, though I want notification to be send without user concern. |
You woudn't have to make .bash_profile owned by root, just .bash_login and .bash_logout, and the user could still set their preferences.
|
Hi Mmatt,
I couldn't find .bash_login script in my home directory. Anyway, this will restrict user if he wants to add something for himself in .bash_login and .bash_logout. |
I can see why you don't want to put root owned files in user directories (it would annoy me as a user...). There's also the fact that they could change shell, so you'd need one for each installed. Hmmm, I'll have a think...
|
Well, I'm guessing you would add something like
Code:
trap '. $HOME/.logout;exit' 0 Code:
trap '. /path/to/where/you/want/.logout;exit' 0 |
Thanx Mmatt, now you got the right nerve.
It would be cumbersome to handle each user .bash file and their different shell separately. Therefore I want a single file where I could change and that do all the magic. ;) Especially logout because I am able to manage login notification by calling it through /etc/profile file. But didn't find any way for logout. |
Thanx again Mmatt,
Your last post really worked as I was expecting. Though there is still one small issue, I don't know is this really a Linux or PUTTY issue. When I give "logout" command from Putty I get the notification script executes but the Putty shell still remains open and user can execute any command off the record. |
Well we don't want that do we. The other idea I had was to use the system log. It records all the stuff you're looking for in /var/log/auth.log. I'm not sure how to configure the logger to send you notifications though.
As for putty, I often find the window doesn't close but the session is actually closed. Do the commands definately execute? |
Another point to check is that the user can't unset the trap themselves...
Code:
trap - EXIT A quick test reveals that users can indeed unset the trap. Therefore I suggest the syslog approach would be better. |
Quote:
just go in their ~/.bashrc which you'd source from ~/.bash_login Cheers, Tink |
All times are GMT -5. The time now is 08:13 AM. |