Operating System - HP-UX
1753773 Members
5226 Online
108799 Solutions
New Discussion юеВ

Re: 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??)