I'm using a solution described here to log my shell sessions, by adding this to the end of /etc/bash.bashrc
:
test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f /var/log/shellog/$USER-$(date -u +%Y.%m.%d-%H:%M:%S).${HOSTNAME:-$(hostname)}.$$.log)
This works fine, however, when I exit the shell, I have to exit twice: once from the script, and once from the shell:
Last login: Wed Aug 6 12:43:29 2014 from *****
Script started, file is /var/log/shellog/camilstaps-2014.08.06-10:43:40.cs.localdomain.16048.log
camilstaps@cs:/$ exit
exit
Script done, file is /var/log/shellog/camilstaps-2014.08.06-10:43:40.cs.localdomain.16048.log
camilstaps@cs:/$ exit
exit
I found this, and tried modifying the line in /etc/bash.bashrc
accordingly, but this doesn't change anything:
test "$(ps -ocommand= -p $PPID | awk '{print $1}')" == 'script' || (script -f /var/log/shellog/$USER-$(date -u +%Y.%m.%d-%H:%M:%S).${HOSTNAME:-$(hostname)}.$$.log && exit)
I suppose it's because I have to test
that I'm not in script
already (without the test
it keeps making new script
s). But how can I make that I don't have to exit twice?
ps -ocommand= -p $PPID
return ?script -f /var/log/shellog/camilstaps-2014.08.06-11:12:11.cs.localdomain.16164.log
script
. Everything after||
will never get executed.()
will run in a subshell. This means another process is created. Read more about it here: mywiki.wooledge.org/SubShell