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.)

9 comments:

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

    ReplyDelete
  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.

    ReplyDelete
  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.

    ReplyDelete
  4. Why not use the 'uptime' command?

    ReplyDelete
  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 :)

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

    ReplyDelete
  7. Saw this linked from http://www.shell-fu.org/lister.php?id=573

    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!

    ReplyDelete
  8. Its more better tuptime, report the time between days.
    http://sourceforge.net/projects/tuptime

    ReplyDelete