LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-21-2009, 05:42 AM   #1
raj_4884
LQ Newbie
 
Registered: Sep 2003
Location: India
Posts: 5

Rep: Reputation: 0
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...
 
Old 07-21-2009, 06:20 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
Old 07-21-2009, 06:24 AM   #3
raj_4884
LQ Newbie
 
Registered: Sep 2003
Location: India
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 07-21-2009, 06:31 AM   #4
mmatt
Member
 
Registered: Nov 2005
Location: UK
Distribution: archlinux
Posts: 90

Rep: Reputation: 19
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.
 
Old 07-21-2009, 06:38 AM   #5
raj_4884
LQ Newbie
 
Registered: Sep 2003
Location: India
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 07-21-2009, 06:43 AM   #6
mmatt
Member
 
Registered: Nov 2005
Location: UK
Distribution: archlinux
Posts: 90

Rep: Reputation: 19
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...
 
Old 07-21-2009, 06:51 AM   #7
mmatt
Member
 
Registered: Nov 2005
Location: UK
Distribution: archlinux
Posts: 90

Rep: Reputation: 19
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.
 
Old 07-21-2009, 06:56 AM   #8
raj_4884
LQ Newbie
 
Registered: Sep 2003
Location: India
Posts: 5

Original Poster
Rep: Reputation: 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.
 
Old 07-21-2009, 07:16 AM   #9
raj_4884
LQ Newbie
 
Registered: Sep 2003
Location: India
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 07-21-2009, 07:49 AM   #10
mmatt
Member
 
Registered: Nov 2005
Location: UK
Distribution: archlinux
Posts: 90

Rep: Reputation: 19
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?
 
Old 07-21-2009, 08:00 AM   #11
mmatt
Member
 
Registered: Nov 2005
Location: UK
Distribution: archlinux
Posts: 90

Rep: Reputation: 19
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.

Last edited by mmatt; 07-21-2009 at 08:05 AM.
 
Old 07-21-2009, 01:35 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by raj_4884 View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Few questions about Nagios - reboot notification, value=x notification. marccmile Linux - Software 5 06-04-2009 07:44 PM
enlightenment won't logoff mrsolo Linux - Software 2 01-03-2006 04:41 PM
logoff scripts wwnexc Linux - Security 2 09-06-2005 04:24 PM
Force logoff Harlin Linux - General 2 07-24-2005 10:35 PM
E-Mail notification to users via SMS (gateway script ok, but notification script?!?) Riku2015 Linux - Networking 10 03-08-2002 11:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration