- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Is there a way to timestamp commnd history
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2005 09:58 AM
06-04-2005 09:58 AM
is there a way to timestamp the .sh_history details ?
any workaround method is also welcome
thanks
Devesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2005 11:55 AM
06-04-2005 11:55 AM
Re: Is there a way to timestamp commnd history
Here's what I do for the sysadmin's .profile/history
Some of .profile:
# Set up logging
HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1}'`
export HISTFILE
print -s "### login at `/usr/bin/date` ###"
#date >>$HISTFILE
HISTSIZE=5000
export HISTSIZE
# Allow sysadmins to have customized environments.
ENV=${HOME}/.kshrc_`who am i|awk '{ print $1}'`
if [ -f $ENV ]
then
export ENV
else
ENV=${HOME}/.kshrc
export ENV
fi
# Set up shell environment:
set -u # error if undefined variable.
umask 022
# Set up shell variables:
MAIL=/var/mail/root
# don't export, so only login shell checks.
echo "WARNING: YOU ARE SUPERUSER !!\n"
HOST=`uname -n`
PS1="
\$LOGNAME@\$HOST [ \$PWD ]
# ";export PS1
stty erase ^?
trap "$HOME/.logout" 0
# cat /.logout
print -s "### logout at `/usr/bin/date` ###"
Cron:
# date stamp sh_history
0 0,6,12,18 * * * /usr/local/bin/datestamp-root-history > /tmp/datestamp-root-history.log 2>&1
#!/bin/sh
#
# script to add a date stamp to the /.sh_history_$USER
# for those su'ed to root
# Only run from cron once a day
# gwild 2004-10-15 with help from jkittle
#===================================================================
# initialize some variables
#===================================================================
ULOG=/tmp/datestamp-user.log
cat /dev/null > $ULOG
#===========================================================
# Function: TimeStamp
# Description: timestamp the /.sh_history_$USER
# Arguments: none
# Returns: none
#===========================================================
function TimeStamp {
# point to their .sh_history file
# time stamp it
echo "HISTFILE is $HISTFILE"
(export HISTFILE=${HOME}/.sh_history_$UNIQUSER; echo "HISTFILE is $HISTFILE"; print -s "### `/usr/bin/date` $UNIQUSER still logged in as root...###")
unset HISTFILE
echo "HISTFILE after unset is $HISTFILE"
}
#===================================================================
# BEGIN MAIN CODE
#===================================================================
# find parent process of all users signed in as root
for i in `ps -ef |grep "\-sh"|awk '{print $3}'`
do
# just grab the user name
for USER in `ps -ef |grep $i |grep -v root|awk '{print $1}'`
do
echo $USER >> $ULOG
done
done
# get each user only once
for UNIQUSER in `cat $ULOG |sort|uniq`
do
TimeStamp
done
exit 0
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2005 07:13 PM
06-04-2005 07:13 PM
Re: Is there a way to timestamp commnd history
I do like the idea of using the audit files though, that is quite innovative.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2005 12:12 AM
06-05-2005 12:12 AM
Re: Is there a way to timestamp commnd history
a5:/u/usr/merijn 101 > date
Sun Jun 5 14:10:04 METDST 2005
a5:/u/usr/merijn 102 > ls -d .
.
a5:/u/usr/merijn 103 > h 2
102 14:10 ls -d .
103 14:10 h 2
a5:/u/usr/merijn 104 > set | grep hist
histdup erase
histfile /u/usr/merijn/.tcshist
history 100
savehist 100
a5:/u/usr/merijn 105 >
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2005 07:58 PM
06-05-2005 07:58 PM
Re: Is there a way to timestamp commnd history
If it is for loggin purposes, you can try to create a script that does a `tail -f .sh_history` and puts the output in an other file with a timestamp. Be noted this will not be acurate to the second since `tail -f` only peeks every couple of seconds. Then, there is also the buffering for non-interactive i/o, this can create some other offset in the timestamps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 12:40 AM
06-06-2005 12:40 AM
SolutionPut this command into your profile:
trap 'date "+# %c" | read -s' debug
It places time stamps into the .sh_history files:
# Tue Nov 23 13:17:03 2004
whao
# Tue Nov 23 13:17:06 2004
whoami
# Tue Nov 23 13:17:08 2004
vi
# Thu Nov 18 15:29:51 2004.
ls
If you put it into place, then PLEASE increase the HISTSIZE=50000 or more
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2005 01:24 AM
06-06-2005 01:24 AM
Re: Is there a way to timestamp commnd history
Below is the syntax for the root acct. A user does an 'su -' to root and a shell history is created with that user name as returned by 'whoami'. Separate .sh_history files with separate date/time stamps and who did the
'su -'.
# Set up shell variables
HST=`hostname`
USR=`who -um | awk '{print $1}'`
NAME=`whoami'
# Set History File HISTFILE=/home/root/.sh_history_"${HST}"_"${USR}"-as-"${NAME}"_`date +%y%m%d.%
H%M%S_$$`
export HISTFILE