1855278 Members
7488 Online
104109 Solutions
New Discussion

.sh_history

 
SOLVED
Go to solution

.sh_history

Where is the secondary .sh_history file stored that tracks commands when you've logged in to a second session with same ID ? I've noticed that if you work in 2 different sessions the Escape-K doesn't return commands from another session.
4 REPLIES 4
John Bolene
Honored Contributor

Re: .sh_history

I only login with root, but all the history goes in the same file on the same server with multiple logins.
The first esc-k brings back the last command I did in each session, the next esc-k actually reads the file and brings back the combined history commands.
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com
Bruce Regittko_1
Esteemed Contributor
Solution

Re: .sh_history

Hi,

If you view the .sh_history file with cat -v or od, you will notice that it is not entirely text. The "extra" null characters are somehow keeping track of the current session as opposed to the entire file. Too bad the man page for sh-posix(1) doesn't say anything about the format of the .sh_history file.

--Bruce
www.stratech.com/training
Rita C Workman
Honored Contributor

Re: .sh_history

On another site I watch was a similar post:
They asked...
.."I have 3 users using the same login.
I want them to have different command histories, is it possible? If so, how? The shell is k-shell, and system is running 10.20. "

Here's some of the suggestion given that may help you:
..do your users need to save their histories over logoff/re-logon?
1) If not, well, how about a "$HOME/.profile" like this:

#!/usr/bin/ksh
.
. # you stuff stays here...
.

export HISTFILE=$HOME/.sh_history.$$
export HISTSIZE=1000
set -o vi
set -o viraw
trap "rm $HISTFILE" 0
# end of .profile

That way everybody gets his/her own history file (their wish) and at the end of the session it will be removed, hence not clogging your diskspace.

2) If they need to continue with their resp. histories after re-login, but each one stays at his/her PC (I guess), then exchange the following line in the example above and delete the "trap" line:

export HISTFILE=$HOME/.sh_history.$(who -u am I | cut -c52-)

That should do the trick for this second case.

3) And if they do login from different places each and every time you do not have many choices but asking them upon loggin in (same line exchanged as before, but now for multiple lines):

traps=$(trap) #remember the traps
trap "" 1 2 3 15 #stop interrupt keys...
name="" #no default name
while [ -z "$name" ] #repeat until entered
do echo "Enter your name: \c" #ask them
read name #get the answer
done #until they entered a name
export HISTFILE=$HOME/.sh_history.$name #set history file
$traps #reset the traps
unset name traps #forget the helping variables

At least they are forced to enter a name - you just have to make shure they do enter the same name every time ;-)

Hope this helps,
/rcw
Wodisch
Honored Contributor

Re: .sh_history

Hello Rita,

thanks for posting my posting from HPADM without
showing my name ;-)

Wodisch