LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   System running time since first boot (https://www.linuxquestions.org/questions/linux-newbie-8/system-running-time-since-first-boot-924388/)

rahulkya 01-18-2012 04:31 AM

System running time since first boot
 
I want to know to how many hours or days or months my system has been run since the day I installed it.
I know uptime gives the info of current system running time from the boot . But I want the total runtime of system regardless of how many time I boot or reboot..

Thanks in Advance

zhjim 01-18-2012 04:59 AM

I dunno of any way to find out afterwards but you could have a script that runs when you shutdown the machine that print the output of uptime and sums it up with previous values from a file.

rahulkya 01-20-2012 03:37 AM

I have the same thought but don't know much about scripting.. Please help me a little with some dummy script. I will take care of it further..

zhjim 01-20-2012 05:02 AM

Code:

NEW=$(uptime | awk '{print $3" "$4" " $5}')          # gives the days and hours of uptime
OLD=$(cat /tmp/uptime_all)                                  # gets the uptime till now
$NEW + $OLD > /tmp/uptime_all                              # sums up the time and puts it into a file

This (pseudo) script has to be run when you shutdown the machine. Look into /etc/rc0.d or /etc/rc6.d.
Or create a cronjob that runs every 5 Minutes and adds 5 Minutes to a file. This way you'll survive serious outtakes where the machine has to be hard reseted or core dumps.

rahulkya 01-21-2012 02:49 PM

Thanks a lot ..I will go with 5 min cron job..


All times are GMT -5. The time now is 02:03 PM.