Operating System - HP-UX
1832858 Members
3552 Online
110048 Solutions
New Discussion

Re: HISTFILE env variable problems

 
SOLVED
Go to solution
Gary S Taylor
Occasional Advisor

HISTFILE env variable problems

Hi folks,
This is my 1st posting on the ITRC.
Here's my problem.

All local filesystems on a single server.
Assume user login is fred.

System profile /etc/profile sets and exports fred's HISTFILE=/tmp/.sh_history_fred

When fred adds the following to their own .profile

unset HISTFILE
HISTFILE=/home/fred/.sh_history_fred
export HISTFILE

The HISTFILE remains as /tmp/.sh_history_fred when displaying the env after login.

If you add an
echo "$HISTFILE" as the final line in the .profile it shows it set as /home/fred/.sh_history_fred
But as soon as login prompt is back after running .profile the HISTFILE variable is back to /tmp/.sh_history_fred
What's going on ?


10 REPLIES 10
Steven E. Protter
Exalted Contributor

Re: HISTFILE env variable problems

The old HISTFILE is not going to just go away merely by changing the variable.

More important, its obvious that the HISTFILE is being changed elsewhere, after your change.

You can start out with /etc/profile , and look for any source (script, program) called that might change it. Then look at .profile and see if its overriding your session.

When I'm in a hurry I just put my logic on the last line of .profile

Anything in .profile after the HISTFILE called with the dot space . myfile can change the setting.

Its also possible that an application is changing the variable after .profile is running.

You can put a set -x in .profile and get more verbose output.

This is really a detective story, where you look until you find the culprit. Its out there, but it may be hard to find.

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
Gary S Taylor
Occasional Advisor

Re: HISTFILE env variable problems

Here's a full copy of my test .profile for the user:

set -o vi
export HISTSIZE=9999
unset HISTFILE
HISTFILE=/home/fred/.sh_history_fred
export HISTFILE

The HISTFILE still reverts back to /tmp/.sh_history_fred after .profile has run.

Funnily enough /etc/profile exports HISTSIZE=1000
then the users .profile re-sets this variable to equal 9999.
This is changed successfully after .profile has run but still not the value of HISTFILE.

RAC_1
Honored Contributor

Re: HISTFILE env variable problems

check the return code from the unset command.
See what is happeneing.

set -o vi
export HISTSIZE=9999
unset HISTFILE
echo $?
HISTFILE=/home/fred/.sh_history_fred
export HISTFILE

The HISTFILE still reverts back to /tmp/.sh_history_fred after .profile has run.

Funnily enough /etc/profile exports HISTSIZE=1000
then the users .profile re-sets this variable to equal 9999.
This is changed successfully after .profile has run but still not the value of HISTFILE
There is no substitute to HARDWORK
Gary S Taylor
Occasional Advisor

Re: HISTFILE env variable problems

The unset command is working fine.

After adding set -x
as the first line in /etc/profile and the users .profile
I saw the following occur:
+
+
+
USER=`who am i | cut -d\ -f1`
+ + who am i
+ cut -d -f1
USER=fred
HISTFILE=/tmp/.sh_history.$USER
+ HISTFILE=/tmp/.sh_history.fred

So it looks like both profiles run OK then shell jumps out and resets the HISTFILE.

This still occurs when I remove the original HISTFILE assignment in /etc/profile and the re-assignment in the users .profile

Very weird, any ideas ..?


Hein van den Heuvel
Honored Contributor

Re: HISTFILE env variable problems


man sh-posix shows:

"HISTFILE
If this parameter is set when the shell is invoked, its value is the path name of the file that is used to store the command history."

So you could read that to say you have but one chance. On entry and not again. Once the shell is there, setting HISTFILE will not change the actual history file because the shell is not re-invoked. If so, it is reasonable that the variable returns the actual = original history file name versus some un-used redefinition.

Also, when experimenting with scripts to test this, be sure to 'source' them with the extra dot: . ./test

fwiw,
Hein.
Muthukumar_5
Honored Contributor

Re: HISTFILE env variable problems

IT is good to get your first post Gary. Keep posting.

---

Try on /etc/profile file end as,

-- /etc/profile --
if [[ $LOGNAME = "fred" ]]
then
set -x
echo $HISTFILE
export HISTFILE=/home/fred/.sh_history_fred
echo $HISTFILE
set +x
fi

--- /home/fred/.profile --
set -x
echo $HISTFILE
export HISTFILE=/home/fred/.sh_history_real
echo $HISTFILE
set +x

Try to login as fred and you will be notified with changes there.

On the login, your history file will be shown as,
/home/fred/.sh_history_real

Try and tell.

Easy to suggest when don't know about the problem!
john korterman
Honored Contributor

Re: HISTFILE env variable problems

Hi Gary,
I think there is a long-haired explanation in Document id: 4000041319

Try this link:
http://www4.itrc.hp.com/service/cki/docDisplay.do?docLocale=en_US&docId=200000066026078
or look for the document in the tech base.

regards,
John K.
it would be nice if you always got a second chance
john korterman
Honored Contributor
Solution

Re: HISTFILE env variable problems

sorry,
forgot to mention that it suggests using "set -o nolog" in /etc/profile.

regards again,
John K.
it would be nice if you always got a second chance
Gary S Taylor
Occasional Advisor

Re: HISTFILE env variable problems

Thanks John,

I knew I wasn't going mad!

Magic Answer - solved.
Gary S Taylor
Occasional Advisor

Re: HISTFILE env variable problems

closed