Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have Linux desktop. I don't leave it 24/7 turned on. I would like to gather statistics on how much time computer was turned on each day, f.e.:

2012-08-21: 7:52
2012-08-22: 8:43
2012-08-23: 7:36

If computer wasn't turned on, no record is required.

share|improve this question
add comment

4 Answers 4

You can create a script which runs uptime & dumps it into a file.

uptime >> uptime.log

After that setup a cron job for it. To know more about how to create a cron job : Create Cron Job

Or you can sign-up for an online service to do it for you : Uptime Project

share|improve this answer
    
yup, I was thinking about this, maybe even get init.d script to run in shutdown. –  aisbaa Aug 23 '12 at 12:14
    
that's also an option.. so i guess i've answered what you actually needed.. –  aliasgar Aug 23 '12 at 12:30
    
this is really good answer, but I'm looking for more sophisticated solution. Maybe something like workrave, which has this as additional functionality, except I don't need this typing break solution. –  aisbaa Aug 23 '12 at 15:01
add comment

There will be datestamped entries in syslog (/var/log/messages*) you can extract this information from.

You could also add K entries to /etc/rc0.d to, for example, to run logger to add a specific syslog record on shutdown. See http://www.debian-administration.org/articles/212 or equivalent for the Linux distribution you are using

$ vim /etc/init.d/uptime
$ cat /etc/init.d/uptime

# chkconfig: 0 99 1
# description: Record uptime at shutdown.

start() {
        uptime >> /var/log/uptime 2>&1
}

case "$1" in
  start)
        start
        ;;
  *)
        echo Usage: $0 start
        ;;
esac

$ chmod +x /etc/init.d/uptime

$ chkconfig --add uptime

$ chkconfig --list uptime
uptime          0:on    1:off   2:off   3:off   4:off   5:off   6:off

$ ls /etc/rc*d/*uptime*
/etc/rc0.d/S99uptime  /etc/rc3.d/K01uptime  /etc/rc6.d/K01uptime
/etc/rc1.d/K01uptime  /etc/rc4.d/K01uptime
/etc/rc2.d/K01uptime  /etc/rc5.d/K01uptime


$ /etc/rc0.d/S99uptime start

$ cat /var/log/uptime
 13:15:28 up 135 days, 12:06,  1 user,  load average: 0.07, 0.04, 0.01
share|improve this answer
add comment

according to last manual page:

The pseudo user reboot logs in each time the system is rebooted. Thus last reboot will show a log of all reboots since the log file was created.

so last column of #last reboot command gives you uptime history:

#last reboot
reboot   system boot  **************** Sat Sep 21 03:31 - 08:27 (1+04:56)   
reboot   system boot  **************** Wed Aug  7 07:08 - 08:27 (46+01:19)
share|improve this answer
add comment
up vote 0 down vote accepted

I've found similar question on stackoverflow http://stackoverflow.com/questions/79490/linux-uptime-history . Best uptimed seems to be what I want, thank you guys for help.

http://podgorny.cz/moin/Uptimed

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.