Originally posted by: Infohawk
cleverhandle,
Wow. That screwed me. :frown:
The "exit" makes my login automatically logout! In otherwords, ssh and telnet to that account becomes unusable. Used ftp to repair it.
I'm trying to have my ssh session autologout after a certain amount of time, at which time the script .bash_logout is run.
The problem with the autologout variable is that it doesn't run the .bash_logout script. It just exits. My issue is that I need that script to run at logout.
BingBongWongFooey,
Thanks. I tried that. Can't say I really understand what it does it looks good.
When I put that in I get, "no matching processes belonging to you were found" upon login. Am I supposed to replace PROMPT_COMMAND with something? Were there any other variables I missed?
Oh, oops. Didn't think of that.
Basically, $PROMPT_COMMAND is run every time your prompt appears, just before it appears. So every time you run a command (or more accurately, just after one finishes), it sets up a timer for $timeout seconds that will exit once the timer is done. But before it runs that timer, it runs killall sleep to kill the other timer(s) running. && means "if the first command ran successfully, execute the next one and return its exit value." & means "run the command before this in the background." Putting the foo && bar inside of parentheses makes them look like one command to the &.
Anyways.. the problem with your error message is that there isn't always an instance of sleep running (like when you first log in), so killall complains. This will shut it up (changes in bold):
timeout=30 #change this
PROMPT_COMMAND="killall sleep
>/dev/null 2>&1; (sleep $timeout && exit) &"
This is still kinda dirty, because you can only have one shell open like this (and have it actually work), and no other instances of sleep can be running, otherwise they'll get killed. Hrmm..
Ok, here's something you can do.
ln -s /bin/sleep $HOME/.mysleep # do this one interactively, don't put it in your shell init files
Then use this PROMPT_COMMAND:
PROMPT_COMMAND="killall .mysleep >/dev/null 2>&1; ($HOME/.mysleep $timeout && exit) &"
This will make the sleep command run, but appear in ps and whatnot as .mysleep instead of sleep, so you can safely use sleep for whatever.
...however, you can still only use one shell at a time. I think I could get around that too, by regenerating the link on every login and using the shell's pid to determine the filename.. do you ever have more than one login going at once?