I've got a BASH script which runs when a user logs in. When a user logs out the script keeps on running. Which is Bad. I'm wondering if anyone can explain how to make the script die when a user logs out.
I've considered making the script check if the user is still logged in by looking at the output of 'who' but had to scrap that when I discovered that a user logged in via an NX session doesn't show up in the output of 'who'. (Whole other issue.) Also that would just be a workaround to the problem rather than a solution.
The script gets run when GNOME starts like this:
Code:
foo:~ # cat /usr/share/gnome/autostart/why_wont_you_die.desktop
[Desktop Entry]
Type=Application
Name=Test script
Comment=Test script
Exec=/usr/local/sbin/why_wont_you_die
I've tried redirecting stdout/stderr to /dev/null and closing stdin by appending >&- to the end of the Exec line but none of that helped.
The script shows up in the output of pstree like this:
Code:
├─gdm───gdm─┬─X
│ └─gnome-session─┬─bluetooth-apple
│ ├─compiz-manager───compiz───gtk-window-deco
│ ├─gnome-do───3*[{gnome-do}]
│ ├─gnome-keyring-d
│ ├─gnome-panel
│ ├─gpg-agent
│ ├─nautilus
│ ├─pidgin
│ ├─python
│ ├─python─┬─3*[bash]
│ │ ├─gnome-pty-helpe
│ │ └─{python}
│ ├─why_wont_you_di───sleep
The script itself looks like this:
Code:
#!/bin/bash
while true; do
sleep 600
date > /dev/null
done
I wonder if the problem is related to the use of the while true loop though the script exits fine if I use 'kill PID' from the command line.
N.B. this is not actually the script I'm having trouble with as that's rather long, it's a nice short script which does essentially the same thing (sleep for a while and then do something, all wrapped in a while true loop) that demonstrates the problem I'm having.