history timestamp is messed up


 
Thread Tools Search this Thread
Operating Systems Linux history timestamp is messed up
# 1  
Old 06-09-2010
history timestamp is messed up

Hi,
Just wanted to know if anyone else has noted that the time-stamp in the history is all out of whack.Smilie
I've Ubuntu, all patched, and when I ran history, it showed me commands that I ran few weeks ago with today's date. Is this normal?
Here is a snippet:
Code:
....
   85  2010-06-09 09:03:31 ls
   86  2010-06-09 09:03:31 cd ..
   87  2010-06-09 09:03:31 ls
   88  2010-06-09 09:03:31 ls -l
   89  2010-06-09 09:03:31 df -h
   90  2010-06-09 09:03:31 ls
   91  2010-06-09 09:03:31 screen 
....

Now I know ran the above ls and cd a few days ago, but it's showing today's date. In fact, most of them are like that.Smilie
Suggestions?

Nitin
# 2  
Old 06-09-2010
What shell are you using? bash, at least on my ubuntu machines, doesn't seem to have any datestamps at all, although the man page for history(3) does describe datestamps in the structures used for the api.

What file are you quoting above?
# 3  
Old 06-09-2010
I'm using bash.
And the above output is from regular history command.

I also use screen though, don't know how the history merges commands between different terminals.

Thanks,
Nitin

Last edited by nitin; 06-09-2010 at 03:23 PM..
# 4  
Old 06-09-2010
Hmmm. On the Ubuntu machines I have access to, which are admittedly not the most recent releases, the history command doesn't show dates in it's output. The .bash_history file also doesn't have datestamps on my boxes.

Could you run "which history" and "whereis history" and send the results?
# 5  
Old 06-09-2010
The history and fc are bash builin commands, so when I did which history I got nothing.
Code:
root:~$ which history
root:~$ whereis history
history: /usr/share/man/man3/history.3readline.gz
root:~$

I'm getting dates because of this envar:
Code:
HISTTIMEFORMAT=%F %T

I could unset it and then I will see the usual history with number and command next to it. I'm leaning towards this being some kind of a bug!Smilie

Yeah, I tested it with manipulating HISTTIMEFORMAT, and it shows same date and time for all the commands. BTW, the time is synced daily on my Linux box, so it can't be because of that.

Thanks,
Nitin
# 6  
Old 06-09-2010
Quote:
Originally Posted by nitin
I'm getting dates because of this envar:
Code:
HISTTIMEFORMAT=%F %T

I could unset it and then I will see the usual history with number and command next to it. I'm leaning towards this being some kind of a bug!Smilie

Yeah, I tested it with manipulating HISTTIMEFORMAT, and it shows same date and time for all the commands. BTW, the time is synced daily on my Linux box, so it can't be because of that.

Thanks,
Nitin

OK, I think I figured this out.

If you don't have HISTTIMEFORMAT set, but do have a history file, and then set HISTTIMEFORMAT, your history will all show the same time.

If you then set HISTTIMEFORMAT in .bashrc, say, so that it's persistent across sessions, log out, log back in, run some commands, and then run history, you'll see the timestamps being updated correctly.

If, as I wonder if you did, you didn't have HISTTIMEFORMAT set at some time in the past, then set it and expected your previous history entries to have the correct datestamp, it won't work. Essentially, having this variable set acts as a switch to have history _start_ saving datestamp data - if it wasn't set, then it won't save it.

Does that make sense? I may not be expressing this well.
This User Gave Thanks to malcolmpdx For This Post:
# 7  
Old 06-10-2010
You are right about
Quote:
If you don't have HISTTIMEFORMAT set, but do have a history file, and then set HISTTIMEFORMAT, your history will all show the same time.

If you then set HISTTIMEFORMAT in .bashrc, say, so that it's persistent across sessions, log out, log back in, run some commands, and then run history, you'll see the timestamps being updated correctly.
I just tested added HISTTIMEFORMAT in .bashrc of a Redhat server. All my previous commands had time-stamp of the time I ran history after adding HISTTIMEFORMAT. But any new commands had different timestamps. Here is the thing, I didn't set the HISTTIMEFORMAT in Ubuntu. I just re-checked the .bashrc, it already had this:
Code:
export HISTTIMEFORMAT="%F %T "

I really didn't pay attention to history till just now. Well, the current Ubuntu machine has been running for almost a year, and I've not changed any bash profiles or .bashrc. In a nutshell, the time format envar is not very trustworthy, and is confusing at best. I almost had a heart attack thinking someone was doing something on my server. Smilie
It's all good now. Smilie

Thanks,

Nitin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

2. HP-UX

History command with timestamp

Hi, i want to print timestamp of the command along with output of 'history' command. Tried this export HISTTIMEFORMAT='%F %T'. But it did not work still getting history output in general way (line number and command). I'm using HP-UX B.11.23 U ia64. Requesting help in this regard. Thanks. (2 Replies)
Discussion started by: sam_bd
2 Replies

3. UNIX for Dummies Questions & Answers

History to Another file [local user history , but root access]

Hi all, My need is : 1. To know who , when , which command used. 2. Local user should not delete this information. I mean , with an example , i can say i have a user user1 i need to give all the following permissions to user1, : a. A specific directory other than his home... (1 Reply)
Discussion started by: sriky86
1 Replies

4. Ubuntu

Messed up password

I am unable to change my password even in root (recovery mode), or to unlock it. I can still access my account, but without password protection. In GUI Administrator account 'disabled' is displayed. This is what I have done so far: In root:#usermod -U roy usermod:cannot lock /etc/passwd;... (9 Replies)
Discussion started by: Royalist
9 Replies

5. UNIX for Advanced & Expert Users

History to Another file [local user history , but root access]

Hi all, My need is : 1. To know who , when , which command used. 2. Local user should not delete this information. I mean , with an example , i can say i have a user user1 i need to give all the following permissions to user1, : a. A specific directory other than his home... (3 Replies)
Discussion started by: linuxadmin
3 Replies

6. UNIX for Advanced & Expert Users

history timestamp in Solaris

Anyone knows how to display timestamp in Solaris since "HISTIMEFORMAT" variable is not supported in ksh ? (2 Replies)
Discussion started by: linuxgeek
2 Replies

7. UNIX for Dummies Questions & Answers

messed up path

Help!! Seem to have messed up my path, as I keep getting command not found error. Could someone please tell whats wrong or how to fix it. export PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:$PATH ---------- Post updated at 08:34 PM ---------- Previous update was at 07:50 PM ---------- ... (1 Reply)
Discussion started by: davcra
1 Replies

8. AIX

Totally messed up

I have moved the etc/passwd file and we are now unable to get in to Unix - any suggestions? (2 Replies)
Discussion started by: vbagwell
2 Replies

9. Shell Programming and Scripting

I think I have messed up with crontab

Hi Guy, In my system there were some cronjob were already scheduled. and somehow I want to enter one new cronjob with crontab. So I isssue crontab temp.txt. it scheduled that job but now it's showing me only this job with crontab -l. but I can not see the old cronjob list that already set up.... (2 Replies)
Discussion started by: vishalpatel03
2 Replies

10. UNIX for Dummies Questions & Answers

Messed up tar files

I created tar files for directories using this command: tar -cvf * >tarfile what happened was I got a file tarfile with a list of the files and it took the first file in each directory and overwrote it with the actual tar file. I've been trying to figure out since yesterday what I did... (2 Replies)
Discussion started by: Barb
2 Replies
Login or Register to Ask a Question