Re: Need ideas: automating history dump
From: Stephane CHAZELAS (stephane_chazelas@yahoo.fr)
Date: 04/23/03
- Next message: Nils Petter Vaskinn: "Re: Cygwin problem"
- Previous message: Stephane CHAZELAS: "Re: why global variable is lost in sh ?"
- In reply to:(deleted message) Irving Kimura: "Need ideas: automating history dump"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: Stephane CHAZELAS <stephane_chazelas@yahoo.fr> Date: 23 Apr 2003 11:49:14 GMT
Irving Kimura wrote:
> I often have one or more shells (always bash) running for several
> days. I want to automate (e.g. via cron) the dumping of each
> shell's history once a day, or whenever the shell exits normally
> (e.g. via Ctrl-D). Each dump should go to a separate file, unique
> for the date and shell in question (e.g. history.20030422.01),
> and should include all the history since the previous dump for that
> shell.
Use zsh and put in your ~/.zshrc:
HISTSIZE=500
SAVEHIST=50000
setopt INC_APPEND_HISTORY
PERIOD=$(( 24 * 60 * 60 ))
periodic() {
HISTFILE=~/history.`date +%Y%m%d`.$$ &&
}
periodic
(not tested)
Look at other options for history storing:
APPEND_HISTORY <D>
If this is set, zsh sessions will append their history list to the
history file, rather than overwrite it. Thus, multiple parallel
zsh sessions will all have their history lists added to the
history file, in the order they are killed.
EXTENDED_HISTORY <C>
Save each command's beginning timestamp (in seconds since the
epoch) and the duration (in seconds) to the history file. The
format of this prefixed data is:
`:<BEGINNING TIME>:<ELAPSED SECONDS>:<COMMAND>'.
HIST_EXPIRE_DUPS_FIRST
If the internal history needs to be trimmed to add the current
command line, setting this option will cause the oldest history
event that has a duplicate to be lost before losing a unique event
from the list. You should be sure to set the value of HISTSIZE to
a larger number than SAVEHIST in order to give you some room for
the duplicated events, otherwise this option will behave just like
HIST_IGNORE_ALL_DUPS once the history fills up with unique events.
HIST_IGNORE_ALL_DUPS
If a new command line being added to the history list duplicates an
older one, the older command is removed from the list (even if it
is not the previous event).
HIST_IGNORE_DUPS (-h)
Do not enter command lines into the history list if they are
duplicates of the previous event.
HIST_IGNORE_SPACE (-g)
Remove command lines from the history list when the first
character on the line is a space, or when one of the expanded
aliases contains a leading space. Note that the command lingers
in the internal history until the next command is entered before
it vanishes, allowing you to briefly reuse or edit the line. If
you want to make it vanish right away without entering another
command, type a space and press return.
HIST_NO_FUNCTIONS
Remove function definitions from the history list. Note that the
function lingers in the internal history until the next command is
entered before it vanishes, allowing you to briefly reuse or edit
the definition.
HIST_NO_STORE
Remove the history (fc -l) command from the history list when
invoked. Note that the command lingers in the internal history
until the next command is entered before it vanishes, allowing you
to briefly reuse or edit the line.
HIST_REDUCE_BLANKS
Remove superfluous blanks from each command line being added to
the history list.
HIST_SAVE_NO_DUPS
When writing out the history file, older commands that duplicate
newer ones are omitted.
INC_APPEND_HISTORY
This options works like APPEND_HISTORY except that new history
lines are added to the $HISTFILE incrementally (as soon as they are
entered), rather than waiting until the shell is killed. The file
is periodically trimmed to the number of lines specified by
$SAVEHIST, but can exceed this value between trimmings.
SHARE_HISTORY <K>
This option both imports new commands from the history file, and
also causes your typed commands to be appended to the history file
(the latter is like specifying INC_APPEND_HISTORY). The history
lines are also output with timestamps ala EXTENDED_HISTORY (which
makes it easier to find the spot where we left off reading the
file after it gets re-written).
By default, history movement commands visit the imported lines as
well as the local lines, but you can toggle this on and off with
the set-local-history zle binding. It is also possible to create
a zle widget that will make some commands ignore imported
commands, and some include them.
If you find that you want more control over when commands get
imported, you may wish to turn SHARE_HISTORY off,
INC_APPEND_HISTORY on, and then manually import commands whenever
you need them using `fc -RI'.
HIST_APPEND
APPEND_HISTORY (bash compatibility)
-- Stéphane
- Next message: Nils Petter Vaskinn: "Re: Cygwin problem"
- Previous message: Stephane CHAZELAS: "Re: why global variable is lost in sh ?"
- In reply to:(deleted message) Irving Kimura: "Need ideas: automating history dump"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|