1833689 Members
3722 Online
110062 Solutions
New Discussion

.sh_history for root?

 
SOLVED
Go to solution
John Stiles
Frequent Advisor

.sh_history for root?

Hi all,
dumb question. How do you get .sh_history to work
for root? running 11i now, never had to set it before. it works for all users except root.

Thanks,
John
all things must pass
12 REPLIES 12
Paula J Frazer-Campbell
Honored Contributor

Re: .sh_history for root?

Hi

Set it in .profile.

See other users .profile for how.

Paula
If you can spell SysAdmin then you is one - anon
Helen French
Honored Contributor

Re: .sh_history for root?

I would put these two entries in the root profile file - /.profile:

HISTSIZE=4096
HISTFILE=/.sh_history
Life is a promise, fulfill it!
Massimo Bianchi
Honored Contributor

Re: .sh_history for root?

Hi,
remember also the

export EDITOR=vi

line, in addition to the others !

and the logout/login, better from another terminal, just in case you made the wrong change and are not being able to login...

HTH,
Massimo
Enrico P.
Honored Contributor

Re: .sh_history for root?

Hi,
in root' s .profile

export HISTFILE=/.sh_history
export HISTSIZE=100

Try

touch /.sh_history

. ./.profile

Good luck

Enrico
Pete Randall
Outstanding Contributor

Re: .sh_history for root?

John,

We put these entries in /etc/profile so that root and all other users get history access:

HISTFILE=/tmp/.sh_history.$(whoami)
export HISTFILE


Pete

Pete
Steven E. Protter
Exalted Contributor
Solution

Re: .sh_history for root?

From /etc/profile

HISTFILE=$HOME/.sh_history
HISTSIZE=5000

This will implement it for all users.

Its important to save lots of data, especially for root. It helps me remember commands I don't use often and track down mistakes made by other people.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Fragon
Trusted Contributor

Re: .sh_history for root?

I always set HISTSIZE as large as possible to keep more history commands!
Some boxes have more than one root user, when there are some problems, we can review the .sh_history to check what's the wrong operation!
Fortunately, very small .sh_history can keep much history commands!!!!!!

-ux
John Stiles
Frequent Advisor

Re: .sh_history for root?

Thanks all!

I used the /etc/profile method. works great.
added the following lines:
# add history stuff. 6/25/03 js.
HISTFILE=$HOME/.sh_history
HISTSIZE=5000
export HISTFILE

The confusing part for me was that it worked for users but not root. Nothing about history in user .profile, but it is in the .cshrc file for users even though user set to use ksh, it seems to be picking up the settings in .cshrc file.

Thanks for the help.
John
all things must pass
Pete Randall
Outstanding Contributor

Re: .sh_history for root?

John,

You should be exporting HISTSIZE as well!


Pete



Pete
Geoff Wild
Honored Contributor

Re: .sh_history for root?

Just an enhancement...

If you have multiple admins who sign in as root, and you want to track them separately, then this is what we do:

# Set up logging
HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1}'`
date >>$HISTFILE
export HISTFILE
HISTSIZE=500
export HISTSIZE

This creates a root history file for each person who su - to root.

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Armin Kunaschik
Esteemed Contributor

Re: .sh_history for root?

And just a simplification to the enhancement:

HISTFILE=~/.history_$LOGNAME

Far better to understand and faster...

Armin
And now for something completely different...
Bill Hassell
Honored Contributor

Re: .sh_history for root?

One of the 'features' of the POSIX shell (unlike ksh) is that the .sh_history file is not created automatically. So even though HISTFILE has been set, the $HOME/.sh_history file must already exist (touch $HOME/.sh_history). The file is created automatically for normal users.


Bill Hassell, sysadmin