Operating System - HP-UX
1755026 Members
5482 Online
54827 Solutions
New Discussion юеВ

How retrive the commands list issued one week ago

 
Singaram
Advisor

How retrive the commands list issued one week ago

In other words what file does the history command works on. Is there any way to retrive that last one month commands issued by a user.

Thanks
Singaram
8 REPLIES 8
Steven E. Protter
Exalted Contributor

Re: How retrive the commands list issued one week ago

Posix:

/home_directory/.sh_history

For this data to be collected, two variables must be set in the user environment.

HISTFILE=$HOME/.sh_history
HISTSIZE=5000

The actual value in the HISTFILE variable will tell you where the command log is.

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
Karthik S S
Honored Contributor

Re: How retrive the commands list issued one week ago

You can get the list of commands from $HOME/.sh_history. But it is not possible to filter the list of commands based on a tome frame.

-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
RAC_1
Honored Contributor

Re: How retrive the commands list issued one week ago

$HOME/.sh_histoty is the file.

If this has been set in /etc/profile or .profile of the user
There is no substitute to HARDWORK
Michael Tully
Honored Contributor

Re: How retrive the commands list issued one week ago

Unless you have auditing turned on forget it. The $HOME/.sh_history file will record commands etc, but no time of attempt will be recorded. Even this may not work depending on the shell being utilised by the user.
Anyone for a Mutiny ?
Geoff Wild
Honored Contributor

Re: How retrive the commands list issued one week ago

Here's what we do in root's profile:

# Set up logging
HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1}'`
date >>$HISTFILE
export HISTFILE
HISTSIZE=500
export HISTSIZE

That creates a seperate .sh_history for each root user. It time stamps each time they log in...

To go back a month - that would requre using something like cron to echo the date to everyone's .sh_history say at midnight every night - then you would be able to see the commands users used each day....

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Singaram
Advisor

Re: How retrive the commands list issued one week ago

This history file will initialize every time it reaches the max size or continue to store the last 500 commands?

Thanks
Singaram
Patrick Wallek
Honored Contributor

Re: How retrive the commands list issued one week ago

The history file is a FIFO (first in first out) file. So it will keep the last 500, or whatever you set that value to, commands issued.
Michael Schulte zur Sur
Honored Contributor

Re: How retrive the commands list issued one week ago

Hi,

try this

greetings,

Michael

DATE=`date "+%b_%Y"`
if [ ! -f ${HOME}/.shistory_${DATE}.* ]
then
VERSION=1;
else
HISTFILE=`ls $HOME/.shistory_${DATE}.*|tail -1`
VERSION=`expr "${HISTFILE}" : ".*_.........\(.*\)$"`
LCOUNT=`cat ${HISTFILE} | wc -l | awk '{print $1}'`
if [ ${LCOUNT} -gt 4900 ]
then
let VERSION=VERSION+1
fi
fi
HISTFILE=${HOME}/.shistory_${DATE}.${VERSION}
export HISTFILE
HISTSIZE=5000
export HISTSIZE