Operating System - HP-UX
1752421 Members
6066 Online
108788 Solutions
New Discussion юеВ

How To Timestamp the KORN Shell History File

 
SOLVED
Go to solution
Michael Steele_2
Honored Contributor

How To Timestamp the KORN Shell History File

To Whom It May Concern:

If your like me and you've been looking for the BASH 'HISTTIMEFORMAT' equivalent for HPUX KSH, well, here it is and I think this is what your E&Y auditors will be happy to see.
####################################
My .profile File
> cat .profile
set -u # error if undefined variable.
trap "echo 'logout root'" 0 # what to do on exit.
trap 'date "+#%c" | read -s' debug # timestamp .sh_history
export HISTFILE=/tmp/$LOGNAME`date +%m%d%y%H%M%S` # Put it in /tmp

My .sh_history file
AKA /tmp/$LOGNAME030911134105

> cat /tmp/f808636030911134105

trap 'date "+# %c" | read -s' debug
# Wed Mar 9 13:42:24 2011
'date "+# %c"'
# Wed Mar 9 13:42:35 2011
history
# Wed Mar 9 13:42:45 2011
trap 'date "+# %c" | read -s' debug
# Wed Mar 9 13:43:02 2011
hisot
# Wed Mar 9 13:43:38 2011
thi
# Wed Mar 9 13:46:14 2011
history
# Wed Mar 9 13:46:16 2011
dog
# Wed Mar 9 13:46:55 2011
cat
ls -la
# Wed Mar 9 13:47:03 2011
cat /etc/passwd
# Wed Mar 9 13:47:09 2011
history
# Wed Mar 9 13:47:12 2011
cat /etc/group
# Wed Mar 9 13:48:34 2011
history
# Wed Mar 9 13:48:36 2011
cat /etc/fstab
# Wed Mar 9 13:48:43 2011
history
# Wed Mar 9 13:48:45 2011
vgdisplay
# Wed Mar 9 13:48:53 2011
history
# Wed Mar 9 13:48:57 2011
vi .profile
# Wed Mar 9 13:50:25 2011
id
# Wed Mar 9 13:50:28 2011
ps
# Wed Mar 9 13:50:29 2011
exit
# Wed Mar 9 13:50:30 2011
Support Fatherhood - Stop Family Law
24 REPLIES 24
Shibin_2
Honored Contributor

Re: How To Timestamp the KORN Shell History File

Good to see. Unfortunately, when I tried the option, got the following error:

DEBUG : Max recursion reached it's limit, exiting

I am unable to login. :(
Regards
Shibin
Steven Schweda
Honored Contributor

Re: How To Timestamp the KORN Shell History File

> [...] your E&Y auditors will be happy to see.

> [...] # Put it in /tmp

So, anyone can play with it? How happy does
that keep everyone?
Michael Steele_2
Honored Contributor

Re: How To Timestamp the KORN Shell History File

Shibin:
That's interesting. Well if nothing ever worked then you've missed something but if you're saying it worked for awhile and then bombed then its of no use. I'll see if I can recreate the same.
Thanks!




Steven:
Please get back on your Thorazine medication and remember to take your afternoon nappy poo. You'll feel better.
Support Fatherhood - Stop Family Law
Michael Steele_2
Honored Contributor

Re: How To Timestamp the KORN Shell History File

Shibin:

Hey, I've run this now all morning with multiple sessions in root on both pa-risc 11.23 and ia64 11.23 and see none of what you are reporting.

?
Support Fatherhood - Stop Family Law
Steven E. Protter
Exalted Contributor
Solution

Re: How To Timestamp the KORN Shell History File

I think this is a great addition.

Thanks.

I will play with it in the lab. Hopefully next week.

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
Bill Hassell
Honored Contributor

Re: How To Timestamp the KORN Shell History File

Here's a slight mod that makes the history a bit easier to read (YYYYMMDD.HHMMSS):

# trap 'date "+ # %a %Y%m%d.%H%M%S" | read -s' debug
5089 # Thu 20110310.202507
5090 ls
5091 # Thu 20110310.202509
5092 date
5093 # Thu 20110310.202510
5094 bdfmegs
5095 # Thu 20110310.202513
5096 boiotinfo
5097 # Thu 20110310.202514

Now the commands are visible on the left with the timestamps pushed to the right. This is the only line you'll need for .profile to add timestamps to each line in the shell history file. Thanks for posting this technique Michael.


Bill Hassell, sysadmin
Shibin_2
Honored Contributor

Re: How To Timestamp the KORN Shell History File

Michael,

Thanks. I have tested it in another PA RISC, works fine. I hope I can use the same in my AIX machine :) .

Not sure, what happened to the earlier machine. I have to boot into single user mode to recover that now. ( tested in root user .. he he ).
Regards
Shibin
Hakki Aydin Ucar
Honored Contributor

Re: How To Timestamp the KORN Shell History File

I used HP-UX 11iv1 PA-Risc box and worked good, great workaround!
Michael Steele_2
Honored Contributor

Re: How To Timestamp the KORN Shell History File

Yes. I like this better.

-/root> grep trap .profile

trap 'date "+ #%c" | read -s' debug # timestamp .sh_history

Thanks Bill Hassell.

-/root> history
389 # Fri 20110311.081338
390 # Fri 20110311.081338
391 history
392 # Fri 20110311.081341
393 history
394 # Fri 20110311.081346
395 # Fri 20110311.081354
396 history
397 vi .profile
398 . ./.profile
399 #Fri Mar 11 08:14:35 2011
400 #Fri Mar 11 08:14:35 2011
401 #Fri Mar 11 08:14:35 2011
402 #Fri Mar 11 08:14:35 2011
403 #Fri Mar 11 08:14:35 2011
404 history
root@fxgpq506-/root>
Support Fatherhood - Stop Family Law