Reputation: 407
I want to schedule a program that display history of a remote machine and stores it in a file in the local machine with timestamps(i.e which commands were executed when) The code i used is this:
ssh -i private_key user@ip 'export HISTTIMEFORMAT=\"%D-%T \" ; \
export HISTFILE=/home/$user/.bash_history; \
set -o history; history' > myfile.txt
But instead of giving the correct time stamps it puts the present time in front of every command. So if the scheduler runs at say 9 o clock the time stamp for every command is 9 o clock. Where am I going wrong?
Upvotes: 2
Views: 2593
Reputation: 206689
If BASHTIMEFORMAT
isn't set in a session, the timing information is not saved to the history file (otherwise it is saved as a comment in there).
So unless the user you're trying to log has that in his/her environment, you will not get timing information. It is simply not recorded, so impossible to retrieve.
Upvotes: 2