Loading ...
Sorry, an error occurred while loading the content.

Re: history without line numbers

Expand Messages
  • Cameron Simpson
    ... For my own shells I use these two functions: loghistory() { _lh_line= : `date +%Y%m%dT%H%M%S`; $* if [ -n $LOGDIR ] && [ -d $LOGDIR/. ] then echo -E
    Message 1 of 7 , Oct 31, 2009
    • 0 Attachment
      On 31Oct2009 07:30, Dan <hyattdj@...> wrote:
      | The first doesnt fit my need, the second has a fatal flaw.
      | as a stop gap, on my servers that I work on....I will type date, and use
      | the results as a command, which fails but leaves a valid timestamp in
      | the history file.
      | In another OS, the date/history retained the actual date/time of the
      | command.

      For my own shells I use these two functions:

      loghistory()
      {
      _lh_line=": `date +%Y%m%dT%H%M%S`; $*"
      if [ -n "$LOGDIR" ] && [ -d "$LOGDIR/." ]
      then echo -E "$_lh_line" >>"$LOGDIR/shell"
      fi
      }
      hh()
      { grepall ${1+"$@"} <"$LOGDIR/shell"
      }

      I contrive that loghistory gets called on each command from my atprompt()
      function, and hh() is for looking back through the log.

      This way you have a separate timestampted log of all commands, one which
      doesn't get rotated or mangled by the shell's history maintenance.

      I find this quite handy.

      Cheers,
      --
      Cameron Simpson <cs@...> DoD#743
      http://www.cskk.ezoshosting.com/cs/

      Beware of bugs in the above code; I have only proved it correct, not tried it.
      - Donald E. Knuth
    • hyattdj
      Solutions: This line in your .bashrc file will put date stamps on your history commands, great for post mortums, or for grouping commands to document a task
      Message 2 of 7 , Nov 12, 2009
      • 0 Attachment
        Solutions:

        This line in your .bashrc file will put date stamps on your history commands, great for post mortums, or for grouping commands to document a task

        export HISTTIMEFORMAT='%Y-%b-%d::%Hh:%Mm:%Ss'


        this is the history command without line numbers, so you can easily script a task..... fc -nl
        eg. fc -nl > dan_script.bash
        add the header #!/bin/bash
        edit out unnessary lines.
        and you are sometimes done
      Your message has been successfully submitted and would be delivered to recipients shortly.