我正在使用描述的解决方案这里要记录我的 shell 会话,请将其添加到以下内容的末尾/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)
这工作正常,但是,当我退出外壳程序时,我必须退出两次:一次从脚本退出,一次从外壳程序退出:
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
我发现这,并尝试相应地修改该行/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 && exit)
我想这是因为我必须test
这么做,所以我还没有加入script
(没有它test
就会不断创造新的script
)。但我怎样才能让我不必退出两次呢?
答案1
按照要求。以下应该有效
[[ $(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 ;}