Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I need to log PC uptime. How I can do this?

I use uptime for this and I will when ubuntu is shutdown write this command output in a file.

share|improve this question
have you tried steps which i posted – Rahul Patil Dec 26 '12 at 10:13
@RahulPatil Thanks. Yes, i tested it and works fine :). Thanks – chalist Dec 26 '12 at 11:12

2 Answers 2

up vote 1 down vote accepted

If you are using Ubuntu

then add below lines in "/etc/rc0.d/S60umountroot" at the beginning.

echo "$(date) $(/usr/bin/uptime)" >> "${Log}"

or you can simply use logger

logger "UPTIME: $(uptime)"

then it will gives details in /var/log/syslog or /var/log/messages

Note :- Please careful edit this file

If you are using CentOs, then do the same in "/etc/rc.d/rc0.d/S01halt", but note that it should be added in beginning of the file.

share|improve this answer

If you need to track the system uptime behavior, try tuptime It report the historical and statistical running time of the system, keeping it between each reboot.

# tuptime -e
Startup:  1  at  01:30:24 PM 08/10/2015
Uptime:   1 minutes and 24 seconds
Shutdown: OK  at  01:31:48 PM 08/10/2015

Downtime: 6 seconds

Startup:  2  at  01:31:55 PM 08/10/2015
Uptime:   3 days, 20 hours, 15 minutes and 35 seconds

System startups:    2   since   01:30:24 PM 08/10/2015
System shutdowns:   1 ok   -   0 bad
Average uptime:     1 days, 22 hours, 8 minutes and 30 seconds
Average downtime:   3 seconds
Current uptime:     3 days, 20 hours, 15 minutes and 35 seconds   since   01:31:55 PM 08/10/2015
Uptime rate:        100.0 %
Downtime rate:      0.0 %
System uptime:      3 days, 20 hours, 17 minutes and 0 seconds
System downtime:    6 seconds
System life:        3 days, 20 hours, 17 minutes and 6 seconds
share|improve this answer

Your Answer


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.