[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: history configuration



>> On Wed, 29 Feb 2012 00:19:19 +0800, lina <lina.lastname@gmail.com> said:

L> How to configure to make each terminal share one "history"?  I found
L> each terminal saves its own history and no sharing.  Is it possible to
L> let them share?

   You can if you don't mind stretching the definition of "share".  Have a
   look at this page to see how to save your command history to syslog:
      http://jablonskis.org/2011/howto-log-bash-history-to-syslog/

   Here's an example.  I added this to the end of ~/.bashrc to save history
   to my own file and the system log:

      export PROMPT_COMMAND='history -a >(tee -a ~/.bash_history |
        logger -p local2.notice -t "$USER [$$] $SSH_CONNECTION")'

   This sends my history to facility "local2" with priority "notice".
   I fixed syslog so local[25] messages only show up in one place; I already
   use local5 for output from a backup program.  Here's the relevant part
   of /etc/syslog.conf -- backslashes must be at the end of the lines:

      # Log anything (except mail) of level info or higher.
      # Don't log private authentication messages!
      *.info;kern.none;mail.none;\
         authpriv.none;auth.none;local2.none;\
         local5.none;cron.none                   /var/log/messages
      # Auth logfiles are restricted.
      authpriv.*                                 /var/log/secure
      auth.*                                     /var/log/authlog
      # Local logs.
      local0.*                                   /var/log/local0log
      local1.*                                   /var/log/local1log
      local2.*                                   /var/log/local2log
      local3.*                                   /var/log/local3log
      local4.*                                   /var/log/local4log
      local5.*                                   /var/log/local5log
      local6.*                                   /var/log/local6log
      # Cron stuff
      cron.*                                     /var/log/cron

   Here's what my history looks like:

      me% tail -3 /var/log/local2log
      Mar 7 22:09:22 svr1 vogelke [149] 1.2.3.4 46555 5.6.7.8 22: which logger
      Mar 7 22:09:31 svr1 vogelke [149] 1.2.3.4 46555 5.6.7.8 22: echo $PATH
      Mar 7 22:09:44 svr1 vogelke [149] 1.2.3.4 46555 5.6.7.8 22: dir /var/log/local*

      me% tail -3 $HOME/.bash_history
      which logger
      echo $PATH
      dir /var/log/local*

   "1.2.3.4" is where I'm connecting from, "5.6.7.8" (aka "svr1") is the
   host I'm connecting to via SSH.  If you use the Z-shell instead of bash,
   the method is pretty similar -- add this function to the bottom of your
   ~/.zshrc file:

      # Log commands, return codes and the current working directory.
      # Based on:
      #
      #   http://blogs.sun.com/chrisg/entry/logging_commands_in_korn_shell
      #   Logging commands in korn shell
      #   Chris Gerhard
      #   Thu, 2 Mar 2006 09:47:29 -0500
      #
      # Don't try to put local on the x= line.  If you do,
      # any command arguments (i.e., "ls -la") will throw an error:
      #   precmd:local:2: not an identifier: -la
      precmd () {
          typeset -i stat=$?
          local x
          x=$(fc -ln -1)
          local d="$(/bin/pwd)"
          logger -p local2.notice -t "$LOGNAME $$" $stat: $d: \($x\)
      }

   In order to really share this, you'd probably have to write something to
   grub around in the syslog file.

-- 
Karl Vogel                      I don't speak for the USAF or my company

She acts like she's on the phone to avoid certain customers.  One time it rang.
                     --Jimmy Fallon, #mycoworkeriscrazy tweets, 2 Mar 2012


Reply to: