The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
What happens when user logout? yhacks Linux 1 05-15-2008 11:20 PM
Executing script with root privilages from a user login checkpro SCO 1 03-11-2008 03:03 PM
Shell script to find when user su'ed to root jrvilino Shell Programming and Scripting 1 03-05-2008 07:31 AM
root executes a script as another user tads98 Shell Programming and Scripting 1 05-17-2005 05:54 AM
Canīt logout to user inactive lalox UNIX for Dummies Questions & Answers 1 07-31-2004 06:31 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-09-2008
Registered User
 

Join Date: Feb 2008
Posts: 8
run a script on logout by a non-root user

hi ,
i need to run a script that delete files when i logout as a user other than root user .

I have tried out using .bash_logout but that doesnt seem to work , so any alternative for this to be done.

Thanks in advance,
Harsha
Reply With Quote
Forum Sponsor
  #2  
Old 06-10-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
You can set a trap in /etc/profile:

Code:
trap 'rm -f $HOME/.dotfile1 $HOME/anotherfile; exit 0' 0
The trap for "signal 0" will be executed when the shell exits.
Reply With Quote
  #3  
Old 06-16-2008
Registered User
 

Join Date: Feb 2008
Posts: 8
Thats true , but what i need is ,

to write the 'trap rm' command (as mentioned in your reply ), in the file which is accessible by a normal user .

I need to insert this command through my program as a normal user.
(/etc/profile can be changed only by the root!!)

Is there any way out for this prob?
Reply With Quote
  #4  
Old 06-16-2008
Registered User
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 352
Try sourcing the .bash_logout file

Did you source the .bash_logout file..?

If source option is not avalaible, depending on your OS, try this:

Code:
~./bash_logout
Reply With Quote
  #5  
Old 06-16-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
If you want to set a trap for a single user, you can add it to the user's $HOME/.profile

Perhaps you could explain a bit more about the problem you are trying to solve.

If you are using bash and the .bash_logout is not being executed, that is of course also something to look into.
Reply With Quote
  #6  
Old 06-16-2008
Registered User
 

Join Date: Feb 2008
Posts: 8
Need to make a script run from my program which deletes certain files as and when the user logouts from the GNOME log screen.

This program is run by a normal user (not the root user).

If I write the required commands in $HOME/.profile , the files get deleted when ever the user logs in again , but i need to delete the files immediately after the user logs out.

i believe .bash_logout doesnt not work if we use GNOME log screen for logging off.
Reply With Quote
  #7  
Old 06-16-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
You cannot really hook into the shell's login/logout scripts, as those are not invoked the way you would expect in Gnome. In particular, the user might login over the network, and/or run multiple terminals in the Gnome session, each of which is a separate shell session.

Instead, look into how GDM handles X sessions (or your login manager, if it't not GDM).
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0