LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   BASH shell temporary history (https://www.linuxquestions.org/questions/linux-newbie-8/bash-shell-temporary-history-583979/)

WingnutOne 09-11-2007 04:05 PM

BASH shell temporary history
 
When you close a BASH shell, it writes the command history from that session to your $HISTFILE. Where does the shell keep the temporary command history list while the shell is still open?

Thanks!

unSpawn 09-11-2007 04:51 PM

In memory?

WingnutOne 09-12-2007 09:57 AM

Quote:

Originally Posted by unSpawn (Post 2888997)
In memory?

If it is in memory, would it have a filename that could be accessed directly?

(Should I put this question somewhere other than the 'Newbie' forum?)

Matir 09-12-2007 10:09 AM

It is not stored in a file until written to .bash_history.

WingnutOne 09-12-2007 03:15 PM

Quote:

Originally Posted by Matir (Post 2889709)
It is not stored in a file until written to .bash_history.

Maybe I'm showing my newbie-ness here, but I thought everything in a Linux/Unix system existed as a "file".
Whether it's a file or not, is there any way to directly watch for additions to the recent command history list?

unSpawn 09-12-2007 03:23 PM

Maybe tell us why you would want that?

Matir 09-12-2007 04:01 PM

The concept that "everything is a file" might be a bit too broad. In a way it's true: these values are stored in memory, and the entire system memory is accessible as a virtual file in /proc/mem. So I guess you could search through there.

Matir 09-12-2007 04:02 PM

Or, of course, you could just type history and see the entries. :)

WingnutOne 09-14-2007 11:25 AM

Quote:

Originally Posted by unSpawn (Post 2890002)
Maybe tell us why you would want that?

I'm one of several admins on a system which constantly has multiple root login shells open. Occasionally, commands issued by different admins working on similar things will cause unexpected problems which we then have to troubleshoot. This job would be easier if we can see all of the commands that were issued, and the order in which they were issued. It would also be nice - though usually less critical - to be able to retain the command history from a shell that locked up, died, or lost it's connection to the host and wasn't able to add it's recent commands list to the permanent $HISTFILE.
I want to create a command history file that logs commands in from each currently open session "on the fly", so that they appear in the order in which they were issued without having to close out all of the sessions first. The only way I've thought of to do this is to set up a function (something like a 'tail -f') that watches for new additions to each shell's temporary command history and drops them all into a shared file.

(We already have the history file being populated with date/time stamps, courtesy of a suggestion from rjwilmsi on another thread.)

makyo 09-15-2007 12:00 PM

Hi.

Long ago, I often used lastcomm on SunOS to tabulate command use. On some distributions, this appears to be part of package acct. On one BSD system that I use, however, the accounting is either disabled or normal users cannot use the file:
Code:

% lastcomm | less
lastcomm: could not open /var/account/acct: Permission denied

I don't know whether the commands issued are added in real-time.

Still, it might be useful to look into ... cheers, makyo

chrism01 09-16-2007 01:37 AM

How about using the 'script' cmd/utility to record everything: http://www.linux.com/articles/53729


All times are GMT -5. The time now is 03:44 PM.