Re: Automatic save of .history in .cshrc
- In reply to: Xianwen_Chen_(陈贤文): "Automatic save of .history in .cshrc"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 20 Feb 2022 22:07:05 UTC
February 20, 2022 2:23:47 PM CET "Xianwen Chen (陈贤文)" <xchen@live.no> wrote:
Hi!
I set the history to 8000:
set history = 8000
set savehist = (8000 merge)
I would like to move the first 4000 lines of .history to a directory. Let's call the directory ~/.history_archive.
The reason that I don't want to move all the contents of .history, is because I would like to have the recent history for auto completion.
I found out a csh script to partly do what I envisioned, from https://forums.freebsd.org/threads/csh-history-file.65582/:
set HIST="~/.history"
if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` == 2000) then
mv ${HIST} ${HIST}.old
touch ${HIST} && chmod 600 ${HIST}
endif
Would the following csh code be correct? Because csh only saves / appends to ~/.history when I log out, I use greater or equal to as the the condition. When there are 6000 lines or more, I split the .history files into two. The first one has 4000 lines, which will be moved to ~/.history_archive, with a file name that contains time information. The other file is moved to be the current ~/.history.
set HIST="~/.history"
if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` >= 6000) then
split -l 4000 ${HIST}
mv xaa ~/.history_archive/history-`date +"%Y-%m-%d-%H-%M" `
mv xab ${HIST}
chmod 600 ${HIST}
endif
Cheers,
Xianwen
newsyslog does everything your script does:
- monitor
- size-test
- move and replace
- set ownership and permissions
You can then set csh to write out history on hourly basis and newsyslog
will rotate when the size condition is met.
newsyslog.conf(5)
-- Sent with https://mailfence.com Secure and private email