LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Logoff Notification (https://www.linuxquestions.org/questions/linux-newbie-8/logoff-notification-741632/)

raj_4884 07-21-2009 04:42 AM

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... :)

Tinkster 07-21-2009 05:20 AM

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

raj_4884 07-21-2009 05:24 AM

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.

mmatt 07-21-2009 05:31 AM

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.

raj_4884 07-21-2009 05:38 AM

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.

mmatt 07-21-2009 05:43 AM

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...

mmatt 07-21-2009 05:51 AM

Well, I'm guessing you would add something like

Code:

trap '. $HOME/.logout;exit' 0
to /etc/profile if you didn't mind putting it in the user directory. Though you could put it somewhere else:

Code:

trap '. /path/to/where/you/want/.logout;exit' 0
Don't know if this'll work, worth a try though.

raj_4884 07-21-2009 05:56 AM

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.

raj_4884 07-21-2009 06:16 AM

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.

mmatt 07-21-2009 06:49 AM

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?

mmatt 07-21-2009 07:00 AM

Another point to check is that the user can't unset the trap themselves...

Code:

trap - EXIT
You may want to look at a program called swatch, which actively monitors system logs e.g. /var/log/auth.log

A quick test reveals that users can indeed unset the trap. Therefore I suggest the syslog approach would be better.

Tinkster 07-21-2009 12:35 PM

Quote:

Originally Posted by raj_4884 (Post 3614970)
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.

Well ... actually the users individual settings could
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.