1828504 Members
3273 Online
109978 Solutions
New Discussion

shell question

 
SOLVED
Go to solution
joseph wholey
Regular Advisor

shell question

RHEL3... if, as root, you're using bash as your default login shell, and then you issue "ksh -o vi", what file does your command history end up in?
14 REPLIES 14
Ryan Goh
Frequent Advisor

Re: shell question

The command-line history is actually kept in a file, called .bash_history in our login directory. We can read it in a number of ways: by using pico, cat, less, more.

Niels Endres
New Member

Re: shell question

Keep in mind that the .bash_history file is only updated once you logout.
joseph wholey
Regular Advisor

Re: shell question

Unless my environment is set up in a strange way, which I'm pretty sure it's not, my history file updates immediately after the command is issued. But, what I'm really trying to get at is, if you issue "ksh -o vi" and then start issuing commands, you'll see you've started a brand new history file. It does not log to .bash_history. Where does it log? thx.
Erkan Saygili
Occasional Contributor

Re: shell question

Hi,

If i am not mistaken each session can have it's own recorded history, and if you run a:
"env |grep -i histfile" you should find your relevant history file.

I hope this helps.

Regards,
Erkan.
Ryan Goh
Frequent Advisor

Re: shell question

yes, you are right, it only save to .bash_history file after logout.

David Child_1
Honored Contributor

Re: shell question

From the 'ksh' man page;

NOTE: if HISTFILE isn't set, no history file is used. This is different from the original Korn shell, which uses $HOME/.sh_history; in future, pdksh may also use a default history file.

So by default your ksh history is only temporarily stored in a buffer and will be lost when you log out. To make it permanent you can use the following line in ~/.bash_profile (if bash is your login shell);

export HISTFILE=${HOME}/.sh_history (or whatever you want to call it). You will need to logout/login to take affect.

David
Huc_1
Honored Contributor

Re: shell question

Try the following ... this probably where your history file is in ksh.
cat .sh_history

Jean-Pierre Huc
Smile I will feel the difference
spex
Honored Contributor

Re: shell question

Hi Joseph,

To change $HISTFILE for ksh without affecting bash, execute the following from bash:

$ (HISTFILE= && ksh)

PCS
joseph wholey
Regular Advisor

Re: shell question

My ultimate goal is to ensure logging regardless of whether the user issues "ksh -o vi" or not. The default shell for root is bash, when root issues "ksh -o vi", nothing logs regardless of whether you set the suggested parameters or not. thx.
Huc_1
Honored Contributor

Re: shell question

I disagree !!

When as root # I issue a ksh -o vi I find that my history is in the file
.sh_history

please note the dot before file name ".sh_history"

I have done not setup on my ksh enviroment this is default.

Jean-Pierre Huc
Smile I will feel the difference
Ryan Goh
Frequent Advisor

Re: shell question

I still couldn't find where the command history stored before it save to .bash_profile, but I know you save the current command history without logout by typing "history -w" command.

joseph wholey
Regular Advisor

Re: shell question

... and that is because it does not get logged permanently. Only for the life of the session. This seems very basic, however, I've been searching for an answer to this for quite some time and have not been able to find a satisfactory solution. And yes, I know I can force the other SA's to use "ss -u root", but that's not what I'm looking for.
Again, to reiterate the problem: RHEL3, root's default shell is /bin/bash. If user su's to root and issues command "ksh -o vi", their history only logs while they are actively in that session. After they log out, history is gone.
David Child_1
Honored Contributor
Solution

Re: shell question

Joseph,

Sorry for the late reply on this. I got tied up with some projects I'm working on and haven't had a chance to check back.

You can get permanent history as already mentioned. You will just have two history files.

Just add "export HISTFILE=${HOME}/.sh_history" to root's ~/.bashrc file.

When someone logs in as root they will have their bash history (in ~/.bash_history). Then if someone runs 'ksh -o vi' their history will be recorded in ~/.sh_history.

You can technically point HISTFILE to ${HOME}/.bash_history, but it won't work right as the formatting is different.

Also, you might get a little more input from other forum members if you assign points. Members can easily see that you have only assigned points to one out of 94 reponses. Most of the members in the forums will help either way, but it can't hurt.

David
joseph wholey
Regular Advisor

Re: shell question

David,

Thanks for the response. That is exactly what I want. Thank you for the advice as well. I will heed it moving forward.

Regards, Joe