Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
using history command with ssh and getting output with time stamps

Basically i want to get a record of all commands executed on my ssh server, with their correct timestamps. The codes i have tried are :

ssh -i private_key user@ip 'export HISTFILE=~/.bash_history;export HISTTIMEFORMAT='%D-%T' ;set -o history; history' > myfile.txt

When i first login and then use history command, i get all details including date and time. when i use this code however, instead of getting the time at which the command was executed, i get the present time(i.e if i execute this code at 3 o clock all commands will have their timestamps as 3 o clock)

share|improve this question

marked as duplicate by Oliver Salzburg, Sathya May 21 '12 at 11:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
yeah it is. but there by mistake i thought i had found the solution. didnt notice the timestamps were incorrect. So started this thread. –  ganducoder May 21 '12 at 11:27
    
Feel free to edit your original question to update or correct it. It will then be bumped and everyone gets to see it again. No need for a new question :) –  Oliver Salzburg May 21 '12 at 11:29
    
k. @OliverSalzburg it would be more helpful if u would remove the earlier question and let this one stay. –  ganducoder May 21 '12 at 11:49
add comment

1 Answer

up vote 0 down vote accepted

As I said in my answer to your more or less identical question:

If you have not set the HISTTIMEFORMAT environment variable when using a session, the command times will not be saved and you will then of course not be able to see them. By default the current time will be printed as the command time for every command lacking a time indicator.

If you look at the ~/.bash_history file you can see if you have had time stamps activated for the sessions. Every other line will then start with a # followed by the epoch time of the next command.

So: look at the remote ~/.bash_history file. Does it include timestamps on every second line? If not, you have not saved any time stamp information for the commands, and cannot get it displayed either.

You need to set the HISTTIMEFORMAT environment variable on the remote location for every session that you want to log the times for. As a suggestion in e.g. ~/.bash_profile (see the "Invocation" section in man bash for more info on which files are read during startup).

share|improve this answer
    
not more or less, its the same. i thought i would try it out here, since nothing over there worked :D –  ganducoder May 21 '12 at 11:23
    
yeah it has timestamps but with the hash followed by epoch time. i tried setting the histtimeformat variable in .profile .bash_profile /etc/profile. still didnt work. I set HISTTIMEFORMAT by exporting it in these files –  ganducoder May 21 '12 at 11:24
    
You should have the times in epoch format, it is converted and presented in a different way depending on HISTTIMEFORMAT. Just having HISTTIMEFORMAT set will save the epoch times; its value decides how it is presented to the user. –  Daniel Andersson May 21 '12 at 15:35
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.