Last Updated: February 25, 2016
·
350
· blazeeboy

Track your computer open/shutdown times

this is a very simple script, i created to track when did i open and closes my computer, on the long run, i can read these data and analyse it to see detect my usage patterns and how to improve my computer usage for a better work/life balance.

this script uses simple text file as log file, it write the event then the Time of the event in each line, i used integers instead of string for event value so opening pc = 1 , closing = 0 to save space.

Gist : https://gist.github.com/9891800

#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
FILENAME = 'db.txt'
OPEN, CLOSE = 1 , 0

file = File.open(FILENAME, 'a')
file.write "#{OPEN} : #{Time.new}\n"
file.flush

begin
loop { sleep 60 } # sleep for an hour in an endless loop

rescue SystemExit, Interrupt # on exit
file.write "#{CLOSE} : #{Time.new}\n"
file.close
end