Operating System - HP-UX
1827470 Members
2522 Online
109965 Solutions
New Discussion

Re: Shell history not being written to specified history file

 
Brett Simpson
Frequent Advisor

Shell history not being written to specified history file

I have been trying to create an alternative shell history file and my commands are not being written to it, but still to the .sh_history file. I've entered the following in my .profile:

HISTFILE=$HOME/.$LOGNAME"_history"
date>>$HISTFILE
#print -s "### login at `/usr/bin/date` ###"
export HISTFILE
HISTSIZE=500
export HISTSIZE

All I get in my history file is the date/time I log in:

Thu Apr 23 15:47:13 CDT 2009
Fri Apr 24 10:03:04 CDT 2009
Fri Apr 24 10:04:34 CDT 2009

All of the command history is still being stored in .sh_history.

Any ideas?
36 REPLIES 36
Steven E. Protter
Exalted Contributor

Re: Shell history not being written to specified history file

Shalom,

If the home directory is on NFS may not work.

I would try setting it this way:

HISTFILE="${HOME}/.${LOGNAME}_history"

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
Pete Randall
Outstanding Contributor

Re: Shell history not being written to specified history file

Check your environment to make sure it's set as you think:

# env |grep HIST
HISTFILE=/tmp/.sh_history.root


Pete


Pete
Mark S Meadows
Valued Contributor

Re: Shell history not being written to specified history file

Hi Brett,

Try setting the variable in your home account .profile and logging out and back in again and you it should work ok :

vi .profile
~
~
alias checkfs='/home/markme/bin/monitor_fs/check_fs.sh'

HISTFILE=$HOME/.$LOGNAME"_history"
export HISTFILE
~
~

/home/markme# ls -ail .markme*
9381 -rw------- 1 markme users 48 Apr 24 16:53 .markme_history
gba70102:/home/markme#
Administrating HP-UX systems for more years than I care to admit, but still enjoying it (most of the time!).
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

It's not an NFS-mounted directory - it's local.

Here's the output of env|grep HIST:

env|grep HIST
HISTFILE=/home/bsimpson/.bsimpson_history
HISTSIZE=500

Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

Mark,
I made the changes in my /home .profile
Mark S Meadows
Valued Contributor

Re: Shell history not being written to specified history file

Brett,

Sorry - I did not read the original posting thoroughly.

If you have logged logged out and back in again it should be working.

The variable is not set in the /etc/profile with a "readonly" against it, which would prevent it from being amended ?

Regards,

Mark
Administrating HP-UX systems for more years than I care to admit, but still enjoying it (most of the time!).
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

Mark,
There's no reference to HISTFILE or any history in /etc/profile.

I agree that this should work, but can't figure out why it's not!
Pete Randall
Outstanding Contributor

Re: Shell history not being written to specified history file

Unless your shell doesn't invoke .profile?


Pete

Pete
Dennis Handly
Acclaimed Contributor

Re: Shell history not being written to specified history file

>All of the command history is still being stored in .sh_history.

Where are you defining HISTFILE? Near the top of your .profile?

I also use:
set -o nolog # don't save functions in history file
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

Pete,
I believe it's running .profile since the variables I defined there are being assigned.

Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

Dennis,
Very near the top of .profile.
Peter Nikitka
Honored Contributor

Re: Shell history not being written to specified history file

Hi,

do once a
touch $HISTFILE
and re-login.
Then check for updates of this file.

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

Peter,
I just tried that with the same results. Still just getting the date that I logged in.
Dennis Handly
Acclaimed Contributor

Re: Shell history not being written to specified history file

>Still just getting the date that I logged in.

Throw everything in your .profile away.
Just have:
export HISTFILE=$HOME/.${LOGNAME}_history
export HISTFILE=500
date >> $HISTFILE

See if this works.

Ah, you absolutely can't do this:
date >> $HISTFILE

The shell history file is a binary file and you can't fiddle with it.
And I don't really see how to get a command with a date in the history file, unless you type it in.
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

Dennis,
I've tried that and it didn't work either. It wrote nothing to the $HISTFILE that I defined. If I do an echo $HISTFILE, it shows that valus that I defined.

Just keeps writing to the .sh_history file. Is there somewhere else that I need to define the history file that I want to user?
Dennis Handly
Acclaimed Contributor

Re: Shell history not being written to specified history file

>Is there somewhere else that I need to define the history file that I want to use?

No, this works fine for ksh. What shell are you using and are you talking about root?
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

I'm using ksh and it's a non-root account. Here's the update:

I just created the same test user on a different server and it worked great. So, no I'm wondering if something is set up on this server that's stopping it from working. There must be some setting that's preventing it from working.
Dennis Handly
Acclaimed Contributor

Re: Shell history not being written to specified history file

>There must be some setting that's preventing it from working.

Have you removed the corrupted history file?
Is $HOME over NFS?
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

Here's the lastest update:

If I login and then type ksh, then it starts logging to the correct history file. So, it appears that my ksh shell is not being invoked on login?

Any ideas?
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

Dennis,
I don't what you mean be "corrupted" file. It's not using NFS at all.
Dennis Handly
Acclaimed Contributor

Re: Shell history not being written to specified history file

>it appears that my ksh shell is not being invoked on login?

What does $SHELL show (or your shell entry in /etc/passwd) before you switch?
Brett Simpson
Frequent Advisor

Re: Shell history not being written to specified history file

/bin/ksh
Peter Nikitka
Honored Contributor

Re: Shell history not being written to specified history file

Hi,

something of a time long ago comes into my mind:
Tell us please: what is the OS version you use?

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Michael Mike Reaser
Valued Contributor

Re: Shell history not being written to specified history file

Also - please issue the following command and post the string that's output:

$ what /bin/ksh
There's no place like 127.0.0.1

HP-Server-Literate since 1979