public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Questions about History file
@ 2014-01-08 12:10 Tanstaafl
  2014-01-08 14:01 ` Bruce Hill
  2014-01-08 15:56 ` Alan McKinnon
  0 siblings, 2 replies; 6+ messages in thread
From: Tanstaafl @ 2014-01-08 12:10 UTC (permalink / raw
  To: gentoo-user

Hi all,

I routinely am logged into a server with multiple consoles (I log in 
with one (the same) regular user, then su - to root).

This morning I tried to grep roots .bash_history for a command I ran 
some time ago, and it wasn't there. I know I ran it, so I'd like to 
configure my bash history so this doesn't happen again.

Thinking about it a bit, the first issue I see is... when I am running 
multiple consoles, each one having been started by first logging in as 
my normal user, then su - to root, how does this affect the 
.bash_history file? It seems like there would be a collision of some 
kind, maybe result in the last one to log out 'winning' (that 
.bash_history is the one that is saved/stored) or something?

Maybe... would it be possible to use different regular users, then when 
each one does the su - to root, have it create a separate .bash_history 
file based on the original username? That would be perfect.

I was also considering something like setting HISTSIZE=###, then adding 
something to the logrotate.conf file to start rotating the history file, 
so I don't lose anything - but I'm not sure if that would even work.

So, I'm interested in how others do this... especially on a system that 
has multiple users managing it.

Thx... Charles


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] Questions about History file
  2014-01-08 12:10 [gentoo-user] Questions about History file Tanstaafl
@ 2014-01-08 14:01 ` Bruce Hill
  2014-01-08 21:27   ` covici
  2014-01-08 22:08   ` Stroller
  2014-01-08 15:56 ` Alan McKinnon
  1 sibling, 2 replies; 6+ messages in thread
From: Bruce Hill @ 2014-01-08 14:01 UTC (permalink / raw
  To: gentoo-user

On Wed, Jan 08, 2014 at 07:10:10AM -0500, Tanstaafl wrote:
> Hi all,
> 
> I routinely am logged into a server with multiple consoles (I log in 
> with one (the same) regular user, then su - to root).
> 
> This morning I tried to grep roots .bash_history for a command I ran 
> some time ago, and it wasn't there. I know I ran it, so I'd like to 
> configure my bash history so this doesn't happen again.
> 
> Thinking about it a bit, the first issue I see is... when I am running 
> multiple consoles, each one having been started by first logging in as 
> my normal user, then su - to root, how does this affect the 
> .bash_history file? It seems like there would be a collision of some 
> kind, maybe result in the last one to log out 'winning' (that 
> .bash_history is the one that is saved/stored) or something?
> 
> Maybe... would it be possible to use different regular users, then when 
> each one does the su - to root, have it create a separate .bash_history 
> file based on the original username? That would be perfect.
> 
> I was also considering something like setting HISTSIZE=###, then adding 
> something to the logrotate.conf file to start rotating the history file, 
> so I don't lose anything - but I'm not sure if that would even work.
> 
> So, I'm interested in how others do this... especially on a system that 
> has multiple users managing it.
> 
> Thx... Charles

Long ago living in a country far away on computers long since abandoned, some
friendly sysadmin helped me set this up. For quite some time this has been on
my "TO-DO" wishlist, so your query caused me to search the internet:

http://mywiki.wooledge.org/BashFAQ/088

Hope this helps you and I both append our history for all open terminals.

Bruce
-- 
List replies preferred.

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Don't top-post: http://en.wikipedia.org/wiki/Top_post#Top-posting


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] Questions about History file
  2014-01-08 12:10 [gentoo-user] Questions about History file Tanstaafl
  2014-01-08 14:01 ` Bruce Hill
@ 2014-01-08 15:56 ` Alan McKinnon
  2014-01-09 21:00   ` [gentoo-user] " James
  1 sibling, 1 reply; 6+ messages in thread
From: Alan McKinnon @ 2014-01-08 15:56 UTC (permalink / raw
  To: gentoo-user

On 08/01/2014 14:10, Tanstaafl wrote:
> Hi all,
> 
> I routinely am logged into a server with multiple consoles (I log in
> with one (the same) regular user, then su - to root).
> 
> This morning I tried to grep roots .bash_history for a command I ran
> some time ago, and it wasn't there. I know I ran it, so I'd like to
> configure my bash history so this doesn't happen again.
> 
> Thinking about it a bit, the first issue I see is... when I am running
> multiple consoles, each one having been started by first logging in as
> my normal user, then su - to root, how does this affect the
> .bash_history file? It seems like there would be a collision of some
> kind, maybe result in the last one to log out 'winning' (that
> .bash_history is the one that is saved/stored) or something?
> 
> Maybe... would it be possible to use different regular users, then when
> each one does the su - to root, have it create a separate .bash_history
> file based on the original username? That would be perfect.
> 
> I was also considering something like setting HISTSIZE=###, then adding
> something to the logrotate.conf file to start rotating the history file,
> so I don't lose anything - but I'm not sure if that would even work.
> 
> So, I'm interested in how others do this... especially on a system that
> has multiple users managing it.
> 
> Thx... Charles
> 
> 
> 


Most important thing is to understand that a shell history file is
intended as a nice convenience for users. When the shell runs, it keep a
history of that session in RAM, and when the shell exits properly it
simple appends the list to the history file. It is just that simple, but
of course there's no guarantees at all. Two sessions don't exit at
exactly the same time, so as far as I know it's simple fs mechanisms
that prevent clobbering.

If a command that should be in history isn't, then it's that the session
has not yet closed, it does without exiting properly, or the command was
run >500 commands ago.

I don't know of any bash mechanism to easily create and use different
history files depending on which user did the su. You would probably
have to concoct a custom wrapper script for this.

I do know that once, long ago, I tried to get bash to do proper command
logging for our general-purpose gateway hosts that have 500+ users. It
was a nightmare and I eventually concluded that history, logging and
such things are 100% the province of the user and not the sysadmin. It
just caused way more trouble than it solved. I suspect what you are
looking for is very much in the same category.



-- 
Alan McKinnon
alan.mckinnon@gmail.com



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] Questions about History file
  2014-01-08 14:01 ` Bruce Hill
@ 2014-01-08 21:27   ` covici
  2014-01-08 22:08   ` Stroller
  1 sibling, 0 replies; 6+ messages in thread
From: covici @ 2014-01-08 21:27 UTC (permalink / raw
  To: gentoo-user

Bruce Hill <daddy@happypenguincomputers.com> wrote:

> On Wed, Jan 08, 2014 at 07:10:10AM -0500, Tanstaafl wrote:
> > Hi all,
> > 
> > I routinely am logged into a server with multiple consoles (I log in 
> > with one (the same) regular user, then su - to root).
> > 
> > This morning I tried to grep roots .bash_history for a command I ran 
> > some time ago, and it wasn't there. I know I ran it, so I'd like to 
> > configure my bash history so this doesn't happen again.
> > 
> > Thinking about it a bit, the first issue I see is... when I am running 
> > multiple consoles, each one having been started by first logging in as 
> > my normal user, then su - to root, how does this affect the 
> > .bash_history file? It seems like there would be a collision of some 
> > kind, maybe result in the last one to log out 'winning' (that 
> > .bash_history is the one that is saved/stored) or something?
> > 
> > Maybe... would it be possible to use different regular users, then when 
> > each one does the su - to root, have it create a separate .bash_history 
> > file based on the original username? That would be perfect.
> > 
> > I was also considering something like setting HISTSIZE=###, then adding 
> > something to the logrotate.conf file to start rotating the history file, 
> > so I don't lose anything - but I'm not sure if that would even work.
> > 
> > So, I'm interested in how others do this... especially on a system that 
> > has multiple users managing it.
> > 
> > Thx... Charles
> 
> Long ago living in a country far away on computers long since abandoned, some
> friendly sysadmin helped me set this up. For quite some time this has been on
> my "TO-DO" wishlist, so your query caused me to search the internet:
> 
> http://mywiki.wooledge.org/BashFAQ/088
> 
> Hope this helps you and I both append our history for all open terminals.


Thanks, I thought history was always appended,but now I know.

-- 
Your life is like a penny.  You're going to lose it.  The question is:
How do
you spend it?

         John Covici
         covici@ccs.covici.com


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [gentoo-user] Questions about History file
  2014-01-08 14:01 ` Bruce Hill
  2014-01-08 21:27   ` covici
@ 2014-01-08 22:08   ` Stroller
  1 sibling, 0 replies; 6+ messages in thread
From: Stroller @ 2014-01-08 22:08 UTC (permalink / raw
  To: gentoo-user

> http://mywiki.wooledge.org/BashFAQ/088

The advice here to use awk to "compress" log files seems a bit dated.

Bash now allows you to set in .bashrc:

   export HISTCONTROL=erasedups

I don't know that there's an "ultimate answer" to history management.

Personally, for years I have had my prompt set to show the history number of the current command, so I can look up on the screen and just enter !505 to reuse a previous comment. I reality, I never use this, but a terminal wouldn't feel like a terminal, for me now, without having numbered prompts up the screen.

More practically I tend to use tmux and open new panes for each task or task group, keeping task sets short and closing the pane when I've done that little job (or sub-job). This allows Bash itself to manage its history more efficiently.

If I need to use a previous command and ctrl-R doesn't easily find it, I tend to just `history | grep hint` to find it.  

I also set HISTSIZE and HISTFILESIZE to 900, so to maximise the number of previous commands available to me by typing only a three digit !321.

Stroller.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [gentoo-user] Re: Questions about History file
  2014-01-08 15:56 ` Alan McKinnon
@ 2014-01-09 21:00   ` James
  0 siblings, 0 replies; 6+ messages in thread
From: James @ 2014-01-09 21:00 UTC (permalink / raw
  To: gentoo-user

Alan McKinnon <alan.mckinnon <at> gmail.com> writes:


> I do know that once, long ago, I tried to get bash to do proper command
> logging for our general-purpose gateway hosts that have 500+ users. It
> was a nightmare and I eventually concluded that history, logging and
> such things are 100% the province of the user and not the sysadmin. It
> just caused way more trouble than it solved. I suspect what you are
> looking for is very much in the same category.


Maybe "script" can be use to parse the syntax strings into a user-defined
log file from the root shell...

You'd most likely want to use the "AND" logic operator of the history
buffer to campare against the "script" generated file to get a
clean copy; or something like that.   Seems like I did something
like that years (decades) ago, but the memory is not what it use
to be..... It should not be that difficult to write something from
scratch.....

good_hunting....

James






^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-01-09 21:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-08 12:10 [gentoo-user] Questions about History file Tanstaafl
2014-01-08 14:01 ` Bruce Hill
2014-01-08 21:27   ` covici
2014-01-08 22:08   ` Stroller
2014-01-08 15:56 ` Alan McKinnon
2014-01-09 21:00   ` [gentoo-user] " James

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox