run a script on logout by a non-root user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting run a script on logout by a non-root user
# 1  
Old 06-09-2008
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
# 2  
Old 06-10-2008
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.
# 3  
Old 06-16-2008
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?
# 4  
Old 06-16-2008
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

# 5  
Old 06-16-2008
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.
# 6  
Old 06-16-2008
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.
# 7  
Old 06-16-2008
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).
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run script automatically on reboot as root user?

Hi friends,,, I am running one server on Ubuntu 12.04 LTS 32-bit, some times my pc restarts automatically, with no reason, I have a script to start server which requires root password. in this directory /myserver/start_server.sh How can I do this ? and some scripts I am having that I... (1 Reply)
Discussion started by: Akshay Hegde
1 Replies

2. Shell Programming and Scripting

Script to run commands as root user

Hello I have a script which is working fine so far to generate HTML file. Now i am wondering how do i include a syntax where it can change itself to root user and execute a specific commands as root user. Please help, Thanks in advance. -Siddhesh (2 Replies)
Discussion started by: Siddheshk
2 Replies

3. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

4. Shell Programming and Scripting

Can root user run chmod 000 permission shell script?

Hi, I have a shell script file which is set to access permission 000. When I login as root (sudo su) and try to run this script, I am getting the Permission denied error. I have read somewhere that root admin user can execute any kind of permission script. Then why this behavior? However, I can... (1 Reply)
Discussion started by: royalibrahim
1 Replies

5. Shell Programming and Scripting

Get current logged in user from a script run as root.

Ok, so, in order to install some dependencies of a program I made, a script has to be run as root. The thing is that I have to copy some things into the home folder of currently logged in user, but the variable $HOME returns '/root' and the $USER returns 'root' :( Is there any way to see who is... (7 Replies)
Discussion started by: hakermania
7 Replies

6. Shell Programming and Scripting

How to run script on logout ?

Hi Everybody, I want to run my own script on logout , i can use .bash_logout file... problem is this will work only for that particular user... i want to know the common file... so that script wil run for all the user... 2. How to run script on Shutdown ? Thanks in advance Anitha (4 Replies)
Discussion started by: anisn2002
4 Replies

7. UNIX for Dummies Questions & Answers

How to allow access to some commands having root privleges to be run bu non root user

hi i am new to unix and i have abig task. i have to \run particular commands having root privileges from a non root user. i know sudo is one of the way but i need sum other approach kindly help Thanks (5 Replies)
Discussion started by: suryashikha
5 Replies

8. Shell Programming and Scripting

How a normal user run a script including root privileaged commands

Dear all Ihave written a script in Hpux9.0, the ecript is working fine if I run it from root command prompt But when I am running it thru /etc/profile or /user/.profile and login as a normal user, the owner of the process running the script is the normal user & hence cant run a root privileaged... (7 Replies)
Discussion started by: initin
7 Replies

9. UNIX for Dummies Questions & Answers

run a script at logout

hi all , Need to a run a program on user logout (using GNOME log screen). Tried using .bash_logout for this purpose but that doesnt seem to work. Similar to .bash_logout is there any script /program which a normal user (other than root ) can edit and run it on their logout? can anybody... (0 Replies)
Discussion started by: harsha10
0 Replies

10. Shell Programming and Scripting

set schedule to run a script at background while logout

Hi, How can I run a script at 9:00am and 6:00pm everyday? Can I run it at background while I logout my account? Please help!! Many Thanks!! (1 Reply)
Discussion started by: happyv
1 Replies
Login or Register to Ask a Question