[Pkg-mc-devel] Bug#498123: Bug#498123: closed by Patrick Winnertz <winnie at debian.org> (cmdline history of parallel sessions)
Michelle Konzack
linux4michelle at tamay-dogan.net
Sat Sep 27 18:15:24 UTC 2008
Am 2008-09-24 23:14:24, schrieb Baurzhan Ismagulov:
> This is certainly interesting. I suppose you mean history -w and history
> -a, don't you?
WRONG, it is
history -a # append only NEW commands from the current session
# to the ~/.bash_history which lock the file
# temporary and this is working since over 8 years.
history -r # read history from the ~/.bash_history file
> But if bash doesn't lock the file, I still don't see how
> this can be "mathematically" correct: If history -a reads the file into
> the memory and writes the new one instead, another session could still
> corrupt the file. Could you please elaborate?
Under X, open 4 XTerms and then write
in Xterm 1: echo "XTerm 1"
in Xterm 2: echo "XTerm 2"
in Xterm 3: echo "XTerm 3"
in Xterm 4: echo "XTerm 4"
then close XTerm 1 and look at the history. You will find the last
entry
echo "XTerm 1"
now close XTerm 4 and you will see, the last entry
echo "XTerm 4"
but the previous entry
echo "XTerm 1"
is gone. Now try to
kill -SIGTERM ${PID_OF_XTERM_2} ${PID_OF_XTERM_3}
and look in the ~/.bash_history where you will find only
echo "XTerm 3"
since the Processes are killed in sequence and Xterm3 is overwriting the
changes from XTerm2.
While reading and writing, the ~/.bash_history will be locked and after
read/write immediately released...
So if you create a function in your ~/.bash_login like
----[ '~/.bash_login' ]-------------------------------------
export HISTFILESIZE=1000
shopt -s cmdhist histappend histverify lithist
histupdate()
{
history -a $1
history -r $1
}
------------------------------------------------------------
and in the XTerm or the Console you can type 'histupdate' and you are
done. Also I have added $1, which give me the option append/read to/from
a specified file. I have had never problems with "The BaSH".
And since I hate duplicated history entries in my ~/.bash_history, I use
----[ '~/.bash_logout' ]------------------------------------
touch ~/.bash_history.tmp
(cat ~/.bash_history) |
while read LINE
do
grep --regexp="$LINE" ~/.bash_history.tmp >/dev/null 2>&1
if [ $? -ne 0 ] ; then
FLAG=true
echo -e "${LINE}" >>~/.bash_history.tmp
fi
done
if [ "${FLAG}" = "true"] ; then
/bin/mv -f ~/.bash_history.tmp ~/.bash_history
else
/bin/rm -f ~/.bash_history.tmp
fi
------------------------------------------------------------
which keep the sequence of the history entries, exactly the first
occurence. OK, I have a better one which use the last enty, but this is
only interesting if you have not more entries as 100-200 and/or a fast
machine since it is complex and NEED ONLY "The BaSH".
Thanks, Greetings and nice Day/Evening
Michelle Konzack
Systemadministrator
24V Electronic Engineer
Tamay Dogan Network
Debian GNU/Linux Consultant
--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
+49/177/9351947 50, rue de Soultz MSN LinuxMichi
+33/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.alioth.debian.org/pipermail/pkg-mc-devel/attachments/20080927/970165a6/attachment.pgp
More information about the Pkg-mc-devel
mailing list