在用户退出后历史信息并不一定写入.bash_history。将.bash_logout放在每个用户的家目录中。
#~/.bash_logout LOGFILE=/tmp/$LOGNAME.$SUDO_USER echo "Here is $LOGNAME $SUDO_USER history for the current session" >>$LOGFILE echo "============================================================">>$LOGFILE echo;echo >>$LOGFILE echo "Marchine:" $HOSTNAME >> $LOGFILE cat ~/.bash_history >> $LOGFILE echo "============================================================">>$LOGFILE mail -s "$LOGNAME-$SUDO_USER bash_history" qfong@xxx <$LOGFILE rm $LOGFILE echo >~/.bash_histroy