Thursday, February 19, 2009

Linux one liner: When did I come to work today?

I'm usually quite tired when I get up in the morning. Beeing a consultant with flexible hours, it is often easy to forget exactly when I got to the office in the morning. So I figured i had to write a script to check when I started my computer. What it does is checking the syslog for the first occurence of todays date. I'm running Ubuntu linux and the syslog file is rotated a while after my computer has started. This is why I'm checking syslog.0.

The magic one liner:

date "+%b %d" | xargs -i grep -m1 -i {} /var/log/syslog.0
|awk '{ print "Today I got to work at " $3 }'

(Syntax plugin didn't handle long lines properly. Remove the and put the entire thing on one line.)


  1. The magic one word : 'uptime' ;-)

  2. Wouldn't "uptime" be much simpler? Gives you the current time and the time your machine was on, so you can see when you turned your machine on, and how long you've been working.

  3. Now that's the beauty of Linux... Below is the Windows version I use every day:
    Click - move mouse - wait - click - double click - double click - double click - double click - scroll - too far - scroll back - found.
    I use eye-grep (scroll the window and try to find the info you are looking for) to find the appropriate entry in the Event Viewer.

  4. Why not use the 'uptime' command?

  5. Ok, didn't think of uptime. Why do it the easy way when you can do it the hard way? ;)

    Anyway it beats Windows :)

  6. Hey.. I found it pretty exciting... + 10 in my book.. :)

  7. Saw this linked from

    This is a really good tip though there is an alternative on the shell-fu page linked above for they who don't restart their computer.

    Thanks for the tip!

  8. Its more better tuptime, report the time between days.