LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-18-2012, 05:31 AM   #1
rahulkya
Member
 
Registered: Feb 2009
Location: New Delhi
Distribution: Linux mint,Ubuntu,Debian,RHEL 5,slackware 13.1, free BSD,solaris.
Posts: 186
Blog Entries: 3

Rep: Reputation: 33
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
 
Old 01-18-2012, 05:59 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,467
Blog Entries: 11

Rep: Reputation: 184Reputation: 184
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.
 
Old 01-20-2012, 04:37 AM   #3
rahulkya
Member
 
Registered: Feb 2009
Location: New Delhi
Distribution: Linux mint,Ubuntu,Debian,RHEL 5,slackware 13.1, free BSD,solaris.
Posts: 186
Blog Entries: 3

Original Poster
Rep: Reputation: 33
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..
 
Old 01-20-2012, 06:02 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,467
Blog Entries: 11

Rep: Reputation: 184Reputation: 184
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.
 
1 members found this post helpful.
Old 01-21-2012, 03:49 PM   #5
rahulkya
Member
 
Registered: Feb 2009
Location: New Delhi
Distribution: Linux mint,Ubuntu,Debian,RHEL 5,slackware 13.1, free BSD,solaris.
Posts: 186
Blog Entries: 3

Original Poster
Rep: Reputation: 33
Thanks a lot ..I will go with 5 min cron job..
 
  


Reply

Tags
uptime


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
system time goes backwards or hangs on iMX27 running 2.6.24 roblem Linux - Kernel 1 09-12-2009 02:46 PM
Dual Boot System Fight over system Time TuxLives Mandriva 8 02-14-2008 10:51 AM
/etc/init.d running at boot time chakkerz Linux - General 2 12-10-2005 04:15 AM
system time wrong after running cdrecord-prodvd whysyn Linux - Software 8 01-11-2005 10:19 AM
Running scripts at boot time saintt Linux - Software 1 08-09-2002 06:03 AM


All times are GMT -5. The time now is 02:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration