AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
Expand all | Collapse all

HISTFILE not getting picked up

  • 1.  HISTFILE not getting picked up

    Posted Thu July 15, 2010 08:27 AM

    Originally posted by: DjRobin69


    Hi All
    I added the following to my profile

    IP=`echo $DISPLAY|awk -F":" '{print $1}'`
    readonly HISTFILE=$HOME/.history/.sh_history.$IP
    export HISTFILE

    but when I log in it still uses the standard history file

    echo $HISTFILE
    /home/itmadmin/.history/.sh_history.lap3165524.rtdom.com

    ls -lart
    -rw------- 1 itmadmin itmgroup 6920 15 Jul 13:26 .sh_history

    oslevel
    5.3.0.0

    Any ideas?
    #AIX-Forum


  • 2.  Re: HISTFILE not getting picked up

    Posted Mon July 26, 2010 01:11 AM

    Originally posted by: SystemAdmin


    Check whether HISTFILE has been set previously in /etc/profile or /etc/environment. I assume that the ENV variable is not causing the conflict, as this would change what you saw in the echo command.
    #AIX-Forum


  • 3.  Re: HISTFILE not getting picked up

    Posted Mon July 26, 2010 05:40 AM

    Originally posted by: DjRobin69


    No nothing - I do see this when I enter the env command, maybe it is filtering it out

    A__z=! HISTFILE=! LOGNAME="*TMOUT
    #AIX-Forum


  • 4.  Re: HISTFILE not getting picked up

    Posted Mon July 26, 2010 09:40 PM

    Originally posted by: SystemAdmin


    The HISTFILE mention in the A__z variable is a consequence of your setting it as readonly.

    Just out of interest; what happens if you do not define the HISTFILE variable as readonly. We do not define this variable, only:
    EXTENDED_HISTORY=ON
    HISTSIZE=1000
    HISTDATEFMT=%d/%m/%Y %H:%M:%S
    so that the history is stored in the user .sh_history file.
    #AIX-Forum


  • 5.  Re: HISTFILE not getting picked up

    Posted Tue July 27, 2010 05:13 AM

    Originally posted by: DjRobin69


    It fails with the following message

    . ./.profile
    ksh: %H:%M:%S: not found.

    The extended history does work though and I am now able to see more than the last 150 commands

    I set the HISTFILE to read-only to try and resolve the problem, it was originally set HISTFILE=$HOME/.history/.sh_history.$IP, which failed to work

    Is it possible to use HISTDATEFMT so that it also includes the IP address?
    #AIX-Forum


  • 6.  Re: HISTFILE not getting picked up

    Posted Tue July 27, 2010 05:20 AM

    Originally posted by: DjRobin69


    Changed it too HISTDATEFMT='%d/%m/%Y %H:%M:%S'
    #AIX-Forum


  • 7.  Re: HISTFILE not getting picked up

    Posted Tue July 27, 2010 10:37 PM

    Originally posted by: SystemAdmin


    It sounds as though the HISTFILE variable is set before you execute your .profile, and it is not going to change. Has HISTFILE been set to readonly in /etc/profile or /etc/environment.

    As a workaround, why don't you add a line to your .profile which writes the $IP to whichever history file is used;
    e.g.
    print $IP | read -s

    or you could add the following to /etc/profile
    e.g.
    userDetail=`who am i | tr -s ' '`
    echo "## $userDetail " | read -s
    echo "##\n\n" | read -s

    The above looks strange; but it works. It is handy for administrative logins, which are shared by various users.
    #AIX-Forum


  • 8.  Re: HISTFILE not getting picked up

    Posted Wed July 28, 2010 06:32 AM

    Originally posted by: DjRobin69


    Yes thanks - have already added that - not sure it will convince the auditors to allow us to have a single, shared, privileged account but it's worth a shot
    #AIX-Forum


  • 9.  Re: HISTFILE not getting picked up

    Posted Thu July 29, 2010 01:25 AM

    Originally posted by: SystemAdmin


    Are you able to add the lines you tested in your .profile to /etc/profile instead? You will need to enclose them within an if statement, but this way the HISTFILE variable will be set at login.
    e.g.

    if ; then
    IP=`echo $DISPLAY|awk -F":" '{print $1}'`
    export HISTFILE=/home/itmadmin/.history/.sh_history.$IP
    fi

    I am not sure whether $HOME is available at this stage in the login, so I have expanded it in the code. You may need to replace this.
    #AIX-Forum


  • 10.  Re: HISTFILE not getting picked up

    Posted Thu July 29, 2010 05:19 AM

    Originally posted by: DjRobin69


    Yer I already suggested that to the Admin, but they weren't to happy about me touching /etc/profile as it impacts other users, ah well just gonna have to live with it - thanks for your help
    #AIX-Forum


  • 11.  Re: HISTFILE not getting picked up

    Posted Wed August 04, 2010 11:50 AM

    Originally posted by: DjRobin69


    Found this while looking for something else

    The HISTFILE variable needs to be set to different name before the first history command is created.

    when i check the history I see

    1. #Þ#1280932694#ß#
    if $# -ne 3 ; then
    return 0
    fi
    var=$1 #The enviornment variable to be processed
    addrm_str=$2 #The new path to be used
    action=$3 #Action: a -> add, r -> remove
    if ; then
    return 0 # return without doing anything
    fi
    etc

    So because whatever script is running during logon is writing to the history file - preventing me from changing the name
    #AIX-Forum


  • 12.  Re: HISTFILE not getting picked up

    Posted Wed August 04, 2010 05:44 PM

    Originally posted by: SystemAdmin


    Hi,

    Try adding the following to your .profile

    export HISTFILE=histfile.new; ksh -o vi

    The second shell starts with the new history file. It worked when I tried it.

    Good luck,
    George
    #AIX-Forum


  • 13.  Re: HISTFILE not getting picked up

    Posted Thu August 05, 2010 05:02 AM

    Originally posted by: DjRobin69


    Yes, it worked! Thanks again for your help
    #AIX-Forum