Operating System - HP-UX
1833764 Members
2057 Online
110063 Solutions
New Discussion

Shell History with Date & Timestamps?

 
Lee Harris_5
Valued Contributor

Shell History with Date & Timestamps?

Hi,

I was wondering if anyone knows if it is possible to make the default POSIX shell history file ($HOME/.sh_history) contain not only the commands which have been executed by a user, but also for a date & timestamp to be added to the file to indicate the exact time when a command is run? Is there an easy way to do this, or would this require some clever scripting?

Thanks - Lee
6 REPLIES 6
Chris Wilshaw
Honored Contributor

Re: Shell History with Date & Timestamps?

The solution would require scripting.

The simplest way would be to set the variable up something like

$HOME/.sh_history.`date +%d%m_%H%M`

although this variable would only get refreshed each time the user logged in, so if they log in and stay logged in all day, you'll only get the 1 history file for them.

If you do a search for "timestamp history" on here, you'll get a bunch of links with other ideas

eg:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=896650
Sergejs Svitnevs
Honored Contributor

Re: Shell History with Date & Timestamps?

Muthukumar_5
Honored Contributor

Re: Shell History with Date & Timestamps?

This requirement needs shell level support for adding time and date informations into history details. We can do this with more details as with script command. Change PS1 (prompt variable) to give date + time informations. Start script from /etc/profile file so that it includes which command executed and what is the result obtained from it.

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Shell History with Date & Timestamps?

You can set PS1 (shell prompt) with time and date settings as specified here in,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=888550

thread.

hth.
Easy to suggest when don't know about the problem!
generic_1
Respected Contributor

Re: Shell History with Date & Timestamps?

use
trap 'date "+# %c" | read -s' debug

or turn on auditing
Lee Harris_5
Valued Contributor

Re: Shell History with Date & Timestamps?

Thanks for the answers, haven't managed to get this working the way I want yet, but I think it just needs me to spend a bit more time on it.