1834149 Members
2240 Online
110064 Solutions
New Discussion

problem with history..

 
SOLVED
Go to solution
M. Z. Harbi
Advisor

problem with history..

Hi all,

my problem is when I enter as a root, I can't recall history (Esc + k). when I type "history" the output is as bellow:

"sh: fc: Cannot access or open the history file"

but, when I login as another user, it works fine..

can anyone help me with this...?

thanks
UNDERSTAND life. Do NOT just STAND UNDER it...
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: problem with history..

You first need to export the HISTFILE variable. For example, this is what we use:

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

Then make sure you've done "set -o vi" and that should do it.


Pete




Pete
Umapathy S
Honored Contributor

Re: problem with history..

Harbi,
For root the shell is /sbin/sh. History details are only available with Korn/C shells.

HTH,
Umapathy
Arise Awake and Stop NOT till the goal is Reached!
T G Manikandan
Honored Contributor

Re: problem with history..

HISTFILE=$HOME/.sh_history
Pete Randall
Outstanding Contributor

Re: problem with history..

And - don't forget to export HISTFILE!!!


Pete


Pete
Umapathy S
Honored Contributor

Re: problem with history..

Oops. I am very sorry for my incomplete reply.

-Umapathy
Arise Awake and Stop NOT till the goal is Reached!
Robert-Jan Goossens
Honored Contributor
Solution

Re: problem with history..

HISTFILE=/.sh_history
HISTSIZE=250
export HISTFILE HISTSIZE

Robert-Jan.
Robert A. Pierce
Frequent Advisor

Re: problem with history..

Harbi,


If you run

su root

then you won't have a history file, but if you

su - root

then you will have a history file (if one is set in your /.profile).
Steven E. Protter
Exalted Contributor

Re: problem with history..

There is almost no reason why all users should have a HISTFILE.

It help track operator mistakes, all kinds of good things.

I do it in /etc/profile

HISTFILE=$HOME/.sh_history
HISTSIZE=5000

I know this is similar to other answers, but this is how I do it.

I have had users who were trying to cover their tracks or hide mistakes try and turn it off in their .profile so thats another reason to make it mandatory. To date no applications have been broken by this policy.

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
Robert A. Pierce
Frequent Advisor

Re: problem with history..

Steven,

Good point.

If you have a role account with several users logging in with the same ID, you can keep track of the different histories with something like this:

HDAT=$(date +%y%m%d.%I%M%S)
HWHO=$(who am I -R | /awkc 6)
HTTY=$(tty | tr "/" " "|awk '{ print $NF }')
export HISTFILE=/home/roleacct/.hist/$HDAT.$HTTY.$$.$HWHO.log

This gives you the history files separated by login date, time, tty, process, and hostname/IP address.

Rob