Gentoo Archives: gentoo-user

From: Alan McKinnon <alan.mckinnon@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Questions about History file
Date: Wed, 08 Jan 2014 15:56:26
Message-Id: 52CD7516.3040400@gmail.com
In Reply to: [gentoo-user] Questions about History file by Tanstaafl
1 On 08/01/2014 14:10, Tanstaafl wrote:
2 > Hi all,
3 >
4 > I routinely am logged into a server with multiple consoles (I log in
5 > with one (the same) regular user, then su - to root).
6 >
7 > This morning I tried to grep roots .bash_history for a command I ran
8 > some time ago, and it wasn't there. I know I ran it, so I'd like to
9 > configure my bash history so this doesn't happen again.
10 >
11 > Thinking about it a bit, the first issue I see is... when I am running
12 > multiple consoles, each one having been started by first logging in as
13 > my normal user, then su - to root, how does this affect the
14 > .bash_history file? It seems like there would be a collision of some
15 > kind, maybe result in the last one to log out 'winning' (that
16 > .bash_history is the one that is saved/stored) or something?
17 >
18 > Maybe... would it be possible to use different regular users, then when
19 > each one does the su - to root, have it create a separate .bash_history
20 > file based on the original username? That would be perfect.
21 >
22 > I was also considering something like setting HISTSIZE=###, then adding
23 > something to the logrotate.conf file to start rotating the history file,
24 > so I don't lose anything - but I'm not sure if that would even work.
25 >
26 > So, I'm interested in how others do this... especially on a system that
27 > has multiple users managing it.
28 >
29 > Thx... Charles
30 >
31 >
32 >
33
34
35 Most important thing is to understand that a shell history file is
36 intended as a nice convenience for users. When the shell runs, it keep a
37 history of that session in RAM, and when the shell exits properly it
38 simple appends the list to the history file. It is just that simple, but
39 of course there's no guarantees at all. Two sessions don't exit at
40 exactly the same time, so as far as I know it's simple fs mechanisms
41 that prevent clobbering.
42
43 If a command that should be in history isn't, then it's that the session
44 has not yet closed, it does without exiting properly, or the command was
45 run >500 commands ago.
46
47 I don't know of any bash mechanism to easily create and use different
48 history files depending on which user did the su. You would probably
49 have to concoct a custom wrapper script for this.
50
51 I do know that once, long ago, I tried to get bash to do proper command
52 logging for our general-purpose gateway hosts that have 500+ users. It
53 was a nightmare and I eventually concluded that history, logging and
54 such things are 100% the province of the user and not the sysadmin. It
55 just caused way more trouble than it solved. I suspect what you are
56 looking for is very much in the same category.
57
58
59
60 --
61 Alan McKinnon
62 alan.mckinnon@×××××.com

Replies

Subject Author
[gentoo-user] Re: Questions about History file James <wireless@×××××××××××.com>