Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run shell command at user logout

Posted on 2007-12-05
10
Medium Priority
?
6,342 Views
Last Modified: 2013-12-16
Hello,

I'd like to run the following command every time a user logs out of his Gnome desktop.

rm -Rf /tmp/*

Is there a way to execute this command automatically as soon as they log off? There is only one user on this system at a time.


OS - Ubuntu Linux 7.10


0
Comment
Question by:cacv12000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 20414120
Hi,

For users using bash, add the command to ~/.bash_logout which should be executed when logged out.
0
 
LVL 19

Expert Comment

by:http:// thevpn.guru
ID: 20414368
adding to what omarfarid said ~/.bash_logout refers to /home/youruser/.bash_logout and .bash_logout is a hidden file ...hence the dot in front of the filename. So if you dont change your browser settings you wont see it.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20414423
Thanks shakoush2001 :)

By the way, in which country do you live?
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:cacv12000
ID: 20414471
Hi,

But is .bash_logout supposed to run when logging out of Gnome or just when logging out of a bash shell.
I just tried the above recommendations and it worked great when I logged in through ssh and then logged out but when I log into the Gnome desktop and then log out this does not work.

I tested this by creating a file in /tmp as a normal user called test.file.

The reason I'm going through all this trouble is that we use nomachine nx  to log in remotely to the Gnome desktop. Gnome applets seem to crash intermittently when going through nx but clearing /tmp between connections seems to resolve that issue. I'd like the /tmp clearing to be automated...

Thanks!
0
 
LVL 19

Expert Comment

by:http:// thevpn.guru
ID: 20414591
you can add the code to


/etc/gdm/PostSession/Default

Omar..I am in Lebanon :)..and dont ask about the name it started out as a joke and i got stuck with it since I cant change the display name in EE ;). I have checked your profile and you have got 17 years of experience to show ...I really respect that.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20414977
Thank you shakoush2001 :)

Where I can get more info bout /etc/gdm/PostSession/Default ?
0
 
LVL 19

Expert Comment

by:http:// thevpn.guru
ID: 20415637
Your welcome Omar as for the script..check out this article..simple but it does the job..I personally prefer KDE

http://www.bxlug.be/en/articles/74
0
 
LVL 1

Accepted Solution

by:
FilipeMaia earned 1200 total points
ID: 20426618
Due to the fact that Gnome has no login screen and your are connecting using NX I think you don't have much choices. I think the best solution is to edit the /usr/NX/etc/node.cfg in the servers and change COMMAND_START_GNOME to a script of your own. Something like:

In /usr/NX/etc/node.cfg
COMMAND_START_GNOME=/usr/local/bin/nx-gnome-session


In /usr/NX/etc/node.cfg
#!/bin/bash
/usr/bin/gnome-session
cleanup_script

It's important not to have a '&' in the gnome-session line otherwise the cleanup_script will run at login.
0
 
LVL 1

Expert Comment

by:FilipeMaia
ID: 20426621
On the last script I obviously meant

"In /usr/local/bin/nx-gnome-session" not "In /usr/NX/etc/node.cfg"

My apologies.
0
 

Author Comment

by:cacv12000
ID: 20428059
Excellent Filipe!
The other solutions above do work but not for my particular case. Thanks!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question