<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Script issue with HISTFILE in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866073#M397516</link>
    <description>Argh. Right. HISTFILE is set by invoking user... from cron, root is the invoking user... can't run it from crons by the admin users because su to root requires authentication... ok, I'm stumped for now other than keeping it in separate scripts.</description>
    <pubDate>Tue, 19 Oct 2004 11:36:01 GMT</pubDate>
    <dc:creator>Jeff_Traigle</dc:creator>
    <dc:date>2004-10-19T11:36:01Z</dc:date>
    <item>
      <title>Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866054#M397497</link>
      <description>All admins have a seperate .sh_history file as root.&lt;BR /&gt;&lt;BR /&gt;I want a script that I can run from root's cron, that will timestamp the .sh_history files of all admins still logged in as root once a day.  echo `date` &amp;gt;&amp;gt; sh_history _$USER is not an option as it does NOT issue a newline correctly - IE, the next command a user enters is appened to the line of the date command...&lt;BR /&gt;&lt;BR /&gt;Findings:&lt;BR /&gt;&lt;BR /&gt;Whether I use a function for the routine that sets the HISTFILE or have it striaght in the flow of the srcript, even though the HISTFILE appears to be set (from testing with logging and set -x), the timestamp of each USER only goes into the first USER's .sh_history.&lt;BR /&gt;&lt;BR /&gt;The only work around I found was to have the routine in a seperate script.  That just seems silly to me - must be a way to incorporate this all in a single script.&lt;BR /&gt;&lt;BR /&gt;Attached is a text document with results and the script(s).&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 08:08:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866054#M397497</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-10-19T08:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866055#M397498</link>
      <description>instead of using: echo `date` &amp;gt;&amp;gt; sh_history &lt;BR /&gt;try using print -s $(date)&lt;BR /&gt;&lt;BR /&gt;i beleive the -s option will print to the shell history file instead of to standard out.&lt;BR /&gt;&lt;BR /&gt;The solution was presented previously on the forum.  Not sure how to seach for it though.</description>
      <pubDate>Tue, 19 Oct 2004 08:23:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866055#M397498</guid>
      <dc:creator>c_51</dc:creator>
      <dc:date>2004-10-19T08:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866056#M397499</link>
      <description>If you look at my attachment, you will see I am using print -s - I was the one that posted that in the other thread..&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Tue, 19 Oct 2004 08:28:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866056#M397499</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-10-19T08:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866057#M397500</link>
      <description>Hi Geoff,&lt;BR /&gt;&lt;BR /&gt;Have you tried&lt;BR /&gt;echo `date\n` &amp;gt;&amp;gt; .sh_history&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;&lt;BR /&gt;Regds&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 08:58:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866057#M397500</guid>
      <dc:creator>Sanjay_6</dc:creator>
      <dc:date>2004-10-19T08:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866058#M397501</link>
      <description>Sanjay - yes - tried that - doesn't work.  Just adds a ^J to line - and the first command executed is appended...&lt;BR /&gt;&lt;BR /&gt;print -s only way to go - just would like to do it all in a single script - instead of having to call another script from the first one...&lt;BR /&gt;&lt;BR /&gt;It's almost as if once you set the HISTFILE, it can't be unset (even though the export seems to work) for the duration of that shell?&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Tue, 19 Oct 2004 09:05:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866058#M397501</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-10-19T09:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866059#M397502</link>
      <description>Hai Geoff,&lt;BR /&gt;&lt;BR /&gt; I tried a simple one as,&lt;BR /&gt;&lt;BR /&gt;# sh -x hist.sh&lt;BR /&gt;+ HISTFILE=/home/muthu/.sh_history&lt;BR /&gt;+ TEST=/home/muthu/.sh_history&lt;BR /&gt;+ export HISTFILE=/home/muthu/.sh_history_&lt;BR /&gt;+ echo HISTFILE is /home/muthu/.sh_history_&lt;BR /&gt;HISTFILE is /home/muthu/.sh_history_&lt;BR /&gt;+ /usr/bin/date&lt;BR /&gt;+ print -s Tue Oct 19 01:42:17 MDT 2004  still logged in as root...&lt;BR /&gt;+ unset HISTFILE&lt;BR /&gt;+ export HISTFILE=/home/muthu/.sh_history&lt;BR /&gt;+ echo HISTFILE after unset is /home/muthu/.sh_history&lt;BR /&gt;HISTFILE after unset is /home/muthu/.sh_history&lt;BR /&gt;# cat /home/muthu/.sh_history_&lt;BR /&gt;Tue Oct 19 01:42:17 MDT 2004  still logged in as root...&lt;BR /&gt;&lt;BR /&gt;script&lt;BR /&gt;======&lt;BR /&gt;  # point to their .sh_history file&lt;BR /&gt;  TEST=$HISTFILE&lt;BR /&gt;  export HISTFILE=/home/muthu/.sh_history_&lt;BR /&gt;  # time stamp it&lt;BR /&gt;  echo "HISTFILE is $HISTFILE"&lt;BR /&gt;  print -s "`/usr/bin/date` $USER still logged in as root..."&lt;BR /&gt;  unset HISTFILE&lt;BR /&gt;  export HISTFILE=$TEST&lt;BR /&gt;  echo "HISTFILE after unset is $HISTFILE"&lt;BR /&gt;&lt;BR /&gt; Geoff,&lt;BR /&gt;&lt;BR /&gt;  Try to revert old history file there. Else, if you try with your script again, it will not having default HISTFILE another more there.&lt;BR /&gt;&lt;BR /&gt;    TEST=$HISTFILE&lt;BR /&gt;    &amp;lt;.... snip ....&amp;gt;&lt;BR /&gt;    export HISTFILE=$TEST&lt;BR /&gt;&lt;BR /&gt; It will work there.&lt;BR /&gt;&lt;BR /&gt; I tried on 11.0.&lt;BR /&gt;&lt;BR /&gt;HTH.&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 09:17:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866059#M397502</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-10-19T09:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866060#M397503</link>
      <description>Hi Geoff,&lt;BR /&gt;&lt;BR /&gt;Interesting problem.  Here's a crazy idea.  Maybe you could 'su' to the user and then do the 'print -s', so you would pick the HISTFILE for free and not have to worry about unsetting it.  Something like this:&lt;BR /&gt;&lt;BR /&gt;/bin/su - $USER -c 'print -s "`/usr/bin/date` $USER still logged in as root..."&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 09:17:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866060#M397503</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2004-10-19T09:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866061#M397504</link>
      <description>Just off the cuff, but you're last statement about HISTFILE apparently not being unset made me think of it... have you tried using a different variable name instead? Maybe the shell actually does protect the value of HISTFILE once it's set. (Not sure why it should, but stranger things have been known to happen.) Out of habit, I try to avoid using names the shell uses for its own purposes whenever possible (unless setting something like PATH).</description>
      <pubDate>Tue, 19 Oct 2004 09:23:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866061#M397504</guid>
      <dc:creator>Jeff_Traigle</dc:creator>
      <dc:date>2004-10-19T09:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866062#M397505</link>
      <description>To expand on Jeff's idea, maybe you could try this also:&lt;BR /&gt;&lt;BR /&gt;HISTFILE=${HOME}/.sh_history_$USER  print -s "`/usr/bin/date` $USER still logged in as root..."&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 09:28:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866062#M397505</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2004-10-19T09:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866063#M397506</link>
      <description>&lt;BR /&gt;Muthukumar - no luck:&lt;BR /&gt;&lt;BR /&gt;tail /.sh_history_gwild&lt;BR /&gt;&lt;BR /&gt;vi datestamp-root-history&lt;BR /&gt;datestamp-root-history&lt;BR /&gt;Tue Oct 19 09:04:17 MDT 2004 gwild still logged in as root...&lt;BR /&gt;Tue Oct 19 09:04:17 MDT 2004 user2 still logged in as root...&lt;BR /&gt;tail /.sh_history_gwild&lt;BR /&gt;&lt;BR /&gt;Still adds the timestamp to only my (first) .sh_history...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;John,&lt;BR /&gt;&lt;BR /&gt;The su - USER won't work - as then I would have to su - again to root - and would need pin/fob number...this script is to only timestamp the root's .sh_history file for each admin...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Jeff - has to be HISTFILE - else how does it know which .sh_history to go to?  If not, it will default to root's .sh_history - which we only have for console access..&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Just an FYI - here's a snip from root's .profile:&lt;BR /&gt;&lt;BR /&gt;# Set up logging&lt;BR /&gt;HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1}'`&lt;BR /&gt;export HISTFILE&lt;BR /&gt;print -s "login at `/usr/bin/date`"&lt;BR /&gt;#date &amp;gt;&amp;gt;$HISTFILE&lt;BR /&gt;HISTSIZE=500&lt;BR /&gt;export HISTSIZE&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;And last post by John, that's what's in the script currently...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 10:13:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866063#M397506</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-10-19T10:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866064#M397507</link>
      <description>I have got it now,&lt;BR /&gt;&lt;BR /&gt; The new users are not having environment variable HISTFILE set there while executing there.&lt;BR /&gt;&lt;BR /&gt;we can reproduce with this,&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;#&lt;BR /&gt;# script to add a date stamp to the /.sh_history_$USER&lt;BR /&gt;# for those su'ed to root&lt;BR /&gt;# Only run from cron once a day&lt;BR /&gt;# gwild 2004-10-15&lt;BR /&gt;#set -x&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#===========================================================&lt;BR /&gt;# Function:    TimeStamp&lt;BR /&gt;# Description: timestamp the /.sh_history_$USER&lt;BR /&gt;# Arguments:   none&lt;BR /&gt;# Returns:     none&lt;BR /&gt;#===========================================================&lt;BR /&gt;function TimeStamp {&lt;BR /&gt;  # point to their .sh_history file&lt;BR /&gt;  TEMP=$(su -c $USER -c "echo $HISTFILE")&lt;BR /&gt;  if [[ $? -ne 0 ]]&lt;BR /&gt;  then&lt;BR /&gt;      echo "$USER: Not having history file"&lt;BR /&gt;      exit 1&lt;BR /&gt;  fi&lt;BR /&gt;  echo "$USER history file $HISTFILE&lt;BR /&gt;  export HISTFILE=${HOME}/.sh_history_$USER&lt;BR /&gt;  # time stamp it&lt;BR /&gt;  echo "HISTFILE is $HISTFILE"&lt;BR /&gt;  print -s "`/usr/bin/date` $USER still logged in as root..."&lt;BR /&gt;  unset HISTFILE&lt;BR /&gt;  HISTFILE=$TEMP&lt;BR /&gt;  echo "HISTFILE after unset is $HISTFILE"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#===================================================================&lt;BR /&gt;# BEGIN MAIN CODE&lt;BR /&gt;#===================================================================&lt;BR /&gt;&lt;BR /&gt;# find parent process of all users signed in as root&lt;BR /&gt;for i in `ps -ef |grep "\-sh"|awk '{print $3}'`&lt;BR /&gt;do&lt;BR /&gt;  # just grab the user name&lt;BR /&gt;  USER=`ps -ef |grep $i |grep -v root|awk '{print $1}'`&lt;BR /&gt;  # TimeStamp&lt;BR /&gt;  TimeStamp $USER&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;HTH.</description>
      <pubDate>Tue, 19 Oct 2004 10:31:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866064#M397507</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2004-10-19T10:31:33Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866065#M397508</link>
      <description>Geoff,&lt;BR /&gt;&lt;BR /&gt;Your attachment includes the output of your script running with 'set -x' and using the external script to do your time stamp function.  Can you post the output with 'set -x' for trying it with the function?  I'd be curious to see what the output is.  Specifically, I'd like to see if the $USER variable is getting inside the function correctly each time.  If not, you might try passing it to the function as a parameter.&lt;BR /&gt;&lt;BR /&gt;I realized after I posted my 'su' idea that it wasn't quite what I had in mind.  My second post is different from your script in that it sets the HISTFILE on the command line as opposed to exporting it and then unsetting it.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 10:49:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866065#M397508</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2004-10-19T10:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866066#M397509</link>
      <description>John,&lt;BR /&gt;&lt;BR /&gt;Here's the output using the function:&lt;BR /&gt;&lt;BR /&gt;+ ps -ef&lt;BR /&gt;+ grep \-sh&lt;BR /&gt;+ awk {print $3}&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 11964&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=tstewart&lt;BR /&gt;+ TimeStamp&lt;BR /&gt;HISTFILE is //.sh_history_tstewart&lt;BR /&gt;HISTFILE after unset is&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 8983&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=gwild&lt;BR /&gt;+ TimeStamp&lt;BR /&gt;HISTFILE is //.sh_history_gwild&lt;BR /&gt;HISTFILE after unset is&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 737&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=elocken&lt;BR /&gt;+ TimeStamp&lt;BR /&gt;HISTFILE is //.sh_history_elocken&lt;BR /&gt;HISTFILE after unset is&lt;BR /&gt;+ exit 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Script is:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;#&lt;BR /&gt;# script to add a date stamp to the /.sh_history_$USER&lt;BR /&gt;# for those su'ed to root&lt;BR /&gt;# Only run from cron once a day&lt;BR /&gt;# gwild 2004-10-15&lt;BR /&gt;set -x&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#===========================================================&lt;BR /&gt;# Function:    TimeStamp&lt;BR /&gt;# Description: timestamp the /.sh_history_$USER&lt;BR /&gt;# Arguments:   none&lt;BR /&gt;# Returns:     none&lt;BR /&gt;#===========================================================&lt;BR /&gt;function TimeStamp {&lt;BR /&gt;  # point to their .sh_history file&lt;BR /&gt;  export HISTFILE=${HOME}/.sh_history_$USER&lt;BR /&gt;  # time stamp it&lt;BR /&gt;  echo "HISTFILE is $HISTFILE"&lt;BR /&gt;  print -s "`/usr/bin/date` $USER still logged in as root..."&lt;BR /&gt;  unset HISTFILE&lt;BR /&gt;  echo "HISTFILE after unset is $HISTFILE"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#===================================================================&lt;BR /&gt;# BEGIN MAIN CODE&lt;BR /&gt;#===================================================================&lt;BR /&gt;&lt;BR /&gt;# find parent process of all users signed in as root&lt;BR /&gt;for i in `ps -ef |grep "\-sh"|awk '{print $3}'`&lt;BR /&gt;do&lt;BR /&gt;  # just grab the user name&lt;BR /&gt;  USER=`ps -ef |grep $i |grep -v root|awk '{print $1}'`&lt;BR /&gt;  TimeStamp&lt;BR /&gt;  # /usr/local/bin/datestamp-root-history-TimeStamp $USER&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 10:57:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866066#M397509</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-10-19T10:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866067#M397510</link>
      <description>John,&lt;BR /&gt;&lt;BR /&gt;Tried your way:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;#&lt;BR /&gt;# script to add a date stamp to the /.sh_history_$USER&lt;BR /&gt;# for those su'ed to root&lt;BR /&gt;# Only run from cron once a day&lt;BR /&gt;# gwild 2004-10-15&lt;BR /&gt;set -x&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#===========================================================&lt;BR /&gt;# Function:    TimeStamp&lt;BR /&gt;# Description: timestamp the /.sh_history_$USER&lt;BR /&gt;# Arguments:   none&lt;BR /&gt;# Returns:     none&lt;BR /&gt;#===========================================================&lt;BR /&gt;function TimeStamp {&lt;BR /&gt;  # point to their .sh_history file&lt;BR /&gt;  # export HISTFILE=${HOME}/.sh_history_$USER&lt;BR /&gt;  HISTFILE=${HOME}/.sh_history_$USER&lt;BR /&gt;  # time stamp it&lt;BR /&gt;  echo "HISTFILE is $HISTFILE"&lt;BR /&gt;  print -s "`/usr/bin/date` $USER still logged in as root..."&lt;BR /&gt;  unset HISTFILE&lt;BR /&gt;  echo "HISTFILE after unset is $HISTFILE"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#===================================================================&lt;BR /&gt;# BEGIN MAIN CODE&lt;BR /&gt;#===================================================================&lt;BR /&gt;&lt;BR /&gt;# find parent process of all users signed in as root&lt;BR /&gt;for i in `ps -ef |grep "\-sh"|awk '{print $3}'`&lt;BR /&gt;do&lt;BR /&gt;  # just grab the user name&lt;BR /&gt;  USER=`ps -ef |grep $i |grep -v root|awk '{print $1}'`&lt;BR /&gt;  TimeStamp&lt;BR /&gt;  # /usr/local/bin/datestamp-root-history-TimeStamp $USER&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;exit 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Same thing:&lt;BR /&gt;&lt;BR /&gt;+ ps -ef&lt;BR /&gt;+ grep \-sh&lt;BR /&gt;+ awk {print $3}&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 11964&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=tstewart&lt;BR /&gt;+ TimeStamp&lt;BR /&gt;HISTFILE is //.sh_history_tstewart&lt;BR /&gt;HISTFILE after unset is&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 8983&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=gwild&lt;BR /&gt;+ TimeStamp&lt;BR /&gt;HISTFILE is //.sh_history_gwild&lt;BR /&gt;HISTFILE after unset is&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 737&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=elocken&lt;BR /&gt;+ TimeStamp&lt;BR /&gt;HISTFILE is //.sh_history_elocken&lt;BR /&gt;HISTFILE after unset is&lt;BR /&gt;+ exit 0&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Yet, only .sh_history_tstewart has the timestamp(s):&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# tail /.sh_history_tstewart&lt;BR /&gt;&lt;BR /&gt;Tue Oct 19 09:58:55 MDT 2004 tstewart still logged in as root...&lt;BR /&gt;Tue Oct 19 09:58:55 MDT 2004 gwild still logged in as root...&lt;BR /&gt;Tue Oct 19 09:58:55 MDT 2004 elocken still logged in as root...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 11:03:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866067#M397510</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-10-19T11:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866068#M397511</link>
      <description>Gotcha... I must have missed the previous thread or something... so print -s prints to the history file so HISTFILE must be set and trying to write directly with echo to the history file mangles things in the file. I'm slow some days, but I eventually come around. :)&lt;BR /&gt;&lt;BR /&gt;Well, I did some testing from the command line and it appears that the shell will only use the first setting of HISTFILE as you've observed in your script. (I tried both having it set initially from /.profile and unset initially... both cases print -s would only use the first set value.)&lt;BR /&gt;&lt;BR /&gt;It works when timestamp is a separate script because you unset HISTFILE (or it's not set initially actually since it's running from cron in your case) before calling it. Thus each invocation of the timestamp script sets it and, since it's the first setting for that invocation, the print -s writes to the file you intend. When it's a function within the same script, you're restricted to writing to the file specified in the first setting of HISTFILE.&lt;BR /&gt;&lt;BR /&gt;Given the shell behavior, it doesn't look like you can avoid having separate scripts (or I'm just not ingenius enough today to figure out how to work around it).</description>
      <pubDate>Tue, 19 Oct 2004 11:03:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866068#M397511</guid>
      <dc:creator>Jeff_Traigle</dc:creator>
      <dc:date>2004-10-19T11:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866069#M397512</link>
      <description>Muthukumar - your lastest post with su - $USER didn't work...&lt;BR /&gt;&lt;BR /&gt;Had to modify slightly - as it errored on second root user with:&lt;BR /&gt;&lt;BR /&gt;/usr/local/bin/datestamp-root-history.Muthukumar&lt;BR /&gt;+ ps -ef&lt;BR /&gt;+ grep \-sh&lt;BR /&gt;+ awk {print $3}&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 11964&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=tstewart&lt;BR /&gt;+ TimeStamp tstewart&lt;BR /&gt;tstewart history file //.sh_history_gwild&lt;BR /&gt;HISTFILE is //.sh_history_tstewart&lt;BR /&gt;HISTFILE after unset is (c)Copyright 1983-2000 Hewlett-Packard Co.,  All Rights Reserved.&lt;BR /&gt;(c)Copyright 1979, 1980, 1983, 1985-1993 The Regents of the Univ. of California&lt;BR /&gt;(c)Copyright 1980, 1984, 1986 Novell, Inc.&lt;BR /&gt;(c)Copyright 1986-1992 Sun Microsystems, Inc.&lt;BR /&gt;(c)Copyright 1985, 1986, 1988 Massachusetts Institute of Technology&lt;BR /&gt;(c)Copyright 1989-1993  The Open Software Foundation, Inc.&lt;BR /&gt;(c)Copyright 1986 Digital Equipment Corp.&lt;BR /&gt;(c)Copyright 1990 Motorola, Inc.&lt;BR /&gt;(c)Copyright 1990, 1991, 1992 Cornell University&lt;BR /&gt;(c)Copyright 1989-1991 The University of Maryland&lt;BR /&gt;(c)Copyright 1988 Carnegie Mellon University&lt;BR /&gt;(c)Copyright 1991-2000 Mentat Inc.&lt;BR /&gt;(c)Copyright 1996 Morning Star Technologies, Inc.&lt;BR /&gt;(c)Copyright 1996 Progressive Systems, Inc.&lt;BR /&gt;(c)Copyright 1991-2000 Isogon Corporation, All Rights Reserved.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;                           RESTRICTED RIGHTS LEGEND&lt;BR /&gt;Use, duplication, or disclosure by the U.S. Government is subject to&lt;BR /&gt;restrictions as set forth in sub-paragraph (c)(1)(ii) of the Rights in&lt;BR /&gt;Technical Data and Computer Software clause in DFARS 252.227-7013.&lt;BR /&gt;&lt;BR /&gt;                           Hewlett-Packard Company&lt;BR /&gt;                           3000 Hanover Street&lt;BR /&gt;                           Palo Alto, CA 94304 U.S.A.&lt;BR /&gt;&lt;BR /&gt;Rights for non-DOD U.S. Government Departments and Agencies are as set&lt;BR /&gt;forth in FAR 52.227-19(c)(1,2).&lt;BR /&gt;//.sh_history_gwild&lt;BR /&gt;logout&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 8983&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=gwild&lt;BR /&gt;+ TimeStamp gwild&lt;BR /&gt;ksh: syntax error at line 1 : `(' unexpected&lt;BR /&gt;gwild: Not having history file&lt;BR /&gt;&lt;BR /&gt;So tried without the -:&lt;BR /&gt;&lt;BR /&gt;  TEMP=$(su $USER -c "echo $HISTFILE")&lt;BR /&gt;&lt;BR /&gt; # /usr/local/bin/datestamp-root-history.Muthukumar&lt;BR /&gt;+ ps -ef&lt;BR /&gt;+ grep \-sh&lt;BR /&gt;+ awk {print $3}&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 11964&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=tstewart&lt;BR /&gt;+ TimeStamp tstewart&lt;BR /&gt;tstewart history file //.sh_history_gwild&lt;BR /&gt;HISTFILE is //.sh_history_tstewart&lt;BR /&gt;HISTFILE after unset is //.sh_history_gwild&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 8983&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=gwild&lt;BR /&gt;+ TimeStamp gwild&lt;BR /&gt;gwild history file //.sh_history_gwild&lt;BR /&gt;HISTFILE is //.sh_history_gwild&lt;BR /&gt;HISTFILE after unset is //.sh_history_gwild&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep 737&lt;BR /&gt;+ grep -v root&lt;BR /&gt;+ awk {print $1}&lt;BR /&gt;USER=elocken&lt;BR /&gt;+ TimeStamp elocken&lt;BR /&gt;elocken history file //.sh_history_gwild&lt;BR /&gt;HISTFILE is //.sh_history_elocken&lt;BR /&gt;HISTFILE after unset is //.sh_history_gwild&lt;BR /&gt;+ exit 0&lt;BR /&gt;&lt;BR /&gt;And yet again - it only updates the first /.sh_history_$USER&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 19 Oct 2004 11:08:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866069#M397512</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-10-19T11:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866070#M397513</link>
      <description>Would it be possible to run something like:&lt;BR /&gt;&lt;BR /&gt;su - ${USER} -c "print -s $(date)"&lt;BR /&gt;&lt;BR /&gt;for each user in this script? That would start a new shell with their login environment set (HISTFILE included) and should write to the appropriate file with each invocation.</description>
      <pubDate>Tue, 19 Oct 2004 11:15:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866070#M397513</guid>
      <dc:creator>Jeff_Traigle</dc:creator>
      <dc:date>2004-10-19T11:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866071#M397514</link>
      <description>Jeff - nope - John suggested that above - sorry - has to go to "root's" .sh_history file - not the user's .sh_history...&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Tue, 19 Oct 2004 11:24:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866071#M397514</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2004-10-19T11:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866072#M397515</link>
      <description>I haven't read and grocked all the posts in this thread, so excuse me if I'm covering old ground here.&lt;BR /&gt;&lt;BR /&gt;I did some playing around with some test scripts. It appears that if I group the export of HISTFILE and the print -s into a subshell, it works. Here is an example:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;echo "HISTFILE is $HISTFILE"&lt;BR /&gt;HISAVE=$HISTFILE&lt;BR /&gt;(export HISTFILE=/root/.sh_this3; echo "HISTFILE is $HISTFILE"; print -s "this3"&lt;BR /&gt;)&lt;BR /&gt;(export HISTFILE=/root/.sh_this4; echo "HISTFILE is $HISTFILE";  print -s "this4&lt;BR /&gt;")&lt;BR /&gt;HISTFILE=$HISAVE&lt;BR /&gt;echo "HISTFILE is $HISTFILE"&lt;BR /&gt;&lt;BR /&gt;HTH, John</description>
      <pubDate>Tue, 19 Oct 2004 11:32:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866072#M397515</guid>
      <dc:creator>John Kittel</dc:creator>
      <dc:date>2004-10-19T11:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Script issue with HISTFILE</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866073#M397516</link>
      <description>Argh. Right. HISTFILE is set by invoking user... from cron, root is the invoking user... can't run it from crons by the admin users because su to root requires authentication... ok, I'm stumped for now other than keeping it in separate scripts.</description>
      <pubDate>Tue, 19 Oct 2004 11:36:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-issue-with-histfile/m-p/4866073#M397516</guid>
      <dc:creator>Jeff_Traigle</dc:creator>
      <dc:date>2004-10-19T11:36:01Z</dc:date>
    </item>
  </channel>
</rss>

