1833693 Members
3575 Online
110062 Solutions
New Discussion

re: root shell history

 
SOLVED
Go to solution
Gurcharan Sahota_2
Frequent Advisor

re: root shell history

this must be so obvious but,

how do I enable the shell history for the root user?

setting up a new HPUX RP3440 server and can't seem to figure this one out.

35 REPLIES 35
Chris Wilshaw
Honored Contributor
Solution

Re: re: root shell history

You just need to add the line

HISTFILE=/.sh_history

to /.profile

Robert-Jan Goossens
Honored Contributor

Re: re: root shell history

Hi,

# echo $SHELL
/sbin/sh
# set -o vi

add this to your root .profile

EDITOR=vi
PS1="$(hostname):\$PWD\# "
HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1}'`
HISTSIZE=1000
export EDITOR HISTFILE PS1 HISTSIZE

Regards,
Robert-Jan
Steven E. Protter
Exalted Contributor

Re: re: root shell history

You should do this for all users

HISTSIZE=500
HISTFILE=$HOME/.sh_history
export HISTFILE HISTSIZE

Do it in /etc/profile

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
Devender Khatana
Honored Contributor

Re: re: root shell history

Hi,

Just add these two lines in root's .profile.
export HISTFILE="/Path_to_file/$LOGNAME"
export HISTSIZE=1000

Remove hash from last line in .dtprofile file lying in root's home directory for xterm.


DTSOURCEPROFILE=true

HTH,
Devender
Impossible itself mentions "I m possible"
Enrico P.
Honored Contributor

Re: re: root shell history

Hi,
after the previous modifications in the .profile:

touch /.sh_history
exit from the system and relog in it

Enrico
Rick Garland
Honored Contributor

Re: re: root shell history

Our sysadms who have root access; with each 'su - root' a separate .sh_history is created with the user account name as a part of the .sh_history name.


HST=`hostname`
USR=`who -um | awk '{print $1}'`
NAME=`whoami`# Set History File
HISTFILE=/home/root/.sh_history_"${HST}"_"${USR}"-as-"${NAME}"_`date +%y%m%d.%
H%M%S_$$`
export HISTFILE

As this example shows, each history file has the $USER name associated with it plus they are time/date stamped.

Geoff Wild
Honored Contributor

Re: re: root shell history

I do like Rick:

# Set up logging
HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1}'`
export HISTFILE
print -s "### login at `/usr/bin/date` ###"
#date >>$HISTFILE
HISTSIZE=50000
export HISTSIZE


As well, testing timestamping of all commands:

#trap to timestamp all commands
trap 'date "+# %c" | read -s' debug

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.
D Block 2
Respected Contributor

Re: re: root shell history

for just the "root" user's .profile or "/.profile" filename, we have:

export PS1="$LOGNAME@`hostname`:\$PWD# "
export HISTFILE=.sh_history
Golf is a Good Walk Spoiled, Mark Twain.
C. Beerse_1
Regular Advisor

Re: re: root shell history

Most replies are about setting history variables. Be noted, not all shells do have a history meganism.

Then, specially for root, donnot change the shell to a binary that is not in the root-filesystem. This shell is used in the single-user mode, where only the root-filesystem is available. Hence, donnot change this shell to something that needs libraries outside the root-filesystem...

(this is based on experience, it ruins your day if single-user does not work once you need it.)
make everything as simple as possible, not simpler (A.Einstein??)
Lorenzo Facello
Valued Contributor

Re: re: root shell history

yes G.
obviously don't touch the sh!!!
just insert in the .profile
export HISTFILE=.sh_history
export HISTSIZE=400
export EDITOR=vi

save the file, loguot and login again:
you will have a history file called .sh_history that takes 400 command in history
and you can you also the esc+k command to recall the commands

Regds
LF
Muthukumar_5
Honored Contributor

Re: re: root shell history

You can try as,

set -o $EDITOR
HISTFILE="/root/.sh_history
HISTSIZE=1000

Put this in /etc/profile file and login in new terminal. It will get effect.

hth.
Easy to suggest when don't know about the problem!
Gurcharan Sahota_2
Frequent Advisor

Re: re: root shell history

thanks for the replies,

but esc-k still does not work...

i have stripped the down the .profile in /home/root to this

export HISTFILE=.sh_history
export HISTSIZE=400
export EDITOR=vi

any other reason(s) it doesn't work?

I'm using terminal emulation software - SmarTerm Essential v9.0, could this be causing a problem?
Devender Khatana
Honored Contributor

Re: re: root shell history

Hi,

Possibally there is one of the case.

1. define full path to .sh_history & ensure you can write that file as that user.

2. If your this session uses Graphical display then check .dtprofile in that user's home directory & uncomment last line.

3. Your Shell is not posix as it works only in Posix Shell. Confirm by "cat /etc/passwd |grep your_user". The shall displayed should be /usr/bin/sh in the end of the line.

HTH,
Devender


HTH,
Devender
Impossible itself mentions "I m possible"
Robert-Jan Goossens
Honored Contributor

Re: re: root shell history

Are you using CDE ?

Check if the last line is uncommented in the $HOME/.dtprofile

DTSOURCEPROFILE=true

Robert-Jan
Muthukumar_5
Honored Contributor

Re: re: root shell history

You have to put as,

set -o vi

so that esc+k will get effect.

Add, just close that session and restart the new session. It will get effect.

hth.
Easy to suggest when don't know about the problem!
Devender Khatana
Honored Contributor

Re: re: root shell history

Hi,

#ksh -o vi is not required here. Allthough works.

You can check wheather your two veriales are set by & home of root is generally / not /home/root in HP.

#set |grep -i hist

HTH,
Devender
Impossible itself mentions "I m possible"
Bill Hassell
Honored Contributor

Re: re: root shell history

It[s really important to code the HISTFILE relative to each user:

export HISTFILE=$HOME/.sh_history

As has been mentioned several times in the HP-UX forums, / is a very, very bnad place to have root's $HOME directory. And if HISTFILE=.sh_history, it will only work when you are in the $HOME directory...some root profiles may cd somewhere else...

And you might as well setup a size and an editor:

export HISTSIZE=500
export EDITOR=/usr/bin/vi

Put these lines in /etc/profile and everyone will have .sh_history setup. NOTE: root is unique in that if $HOME/.sh_history does NOT already exist, it will not be created (other users will have .sh_history created though). Just do this as root:

touch $HOME/.sh_history


Now, everything will work--UNLESS you are using Xwindows. Unfortunately, Xwindows defaults to NO /eetc/profile and NO .profile execution for local terminal emulators such as xterm, hpterm and dtterm. To fix this:

echo "*loginShell:true" >> $HOME/.Xdefaults

This solves the rather crazy CDE method of specifying DTSOURCEPROFILE which is only half correct (never sources /etc/profile, only .profile). The loginShell setting makes the terminal emulators work like all classic telnet or ssh logins.

Note also that just typing these variables on the command line won't enable the shell history. It has to be set during /etc/profile or .profile execution.


Bill Hassell, sysadmin
harry d brown jr
Honored Contributor

Re: re: root shell history

You have a potential serious problem, and I hope it's ONLY a TYPO on your part:

You NEVER EVER put the "root" login directory in any place than UNDER / as a regular directory. You can put it in a directorty called /root or /potato, but you NEVER put root under any OTHER MOUNTED directory. PERIOD!

POST the output from the following to VERIFY where the root login directory is:
grep root /etc/passwd

In /etc/profile, I have this at the end:

export HISTFILE=~/.sh_history_`logname`
export HISTSIZE=500000
export PS1="[`logname`@`hostname` "'${PWD}]# '
export EDITOR=vi
set -o vi

As for wether or not your SmarTerm-less software is screwing with "ESC K", try openning a command prompt in WINDOZE and telnet'ing to your box without the use of SmarTerm-less.

If it doesn't work, then please post the output of:

env

stty -a

set



live free or die
harry d brown jr
Live Free or Die
Gurcharan Sahota_2
Frequent Advisor

Re: re: root shell history

no CDE,

running the set | grep -i hist returns nothing...

really puzzeled, I even copied the /etc/profile and /home/root/.profile scripts from out live servers and they don't work either.
harry d brown jr
Honored Contributor

Re: re: root shell history

Please post the output from these commands:


env

set

grep root /etc/passwd



live free or die
harry d brown jr
Live Free or Die
Gurcharan Sahota_2
Frequent Advisor

Re: re: root shell history

root@bddev:/> grep root /etc/passwd
root:3W6KOwzzuMvzg:0:3::/:/sbin/sh
Gurcharan Sahota_2
Frequent Advisor

Re: re: root shell history

file attached for env output.
Devender Khatana
Honored Contributor

Re: re: root shell history

Hi Gurcharan,

Your parameters are not exported. I still insist to check all these.

1. define full path to .sh_history & ensure you can write that file as that user.

2. If your this session uses Graphical display then check .dtprofile in that user's home directory & uncomment last line.

3. Your Shell is not posix as it works only in Posix Shell. Confirm by "cat /etc/passwd |grep root". The shall displayed should be /usr/bin/sh in the end of the line.

HTH,
Devender
Impossible itself mentions "I m possible"
harry d brown jr
Honored Contributor

Re: re: root shell history

YOUR "root" HOME directory is NOT /home/root, THUS you need to make these changes in /etc/profile


live free or die
harry d brown jr

Live Free or Die