LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices

Reply
 
LinkBack Search this Thread
Old 09-28-2012, 12:32 AM   #1
manoj.linux
Member
 
Registered: Aug 2007
Posts: 219

Rep: Reputation: 15
Question Finding Uptime of Server.


Hi,

I would like to is it possible to find out uptime of server after server rebooting?
 
Old 09-28-2012, 12:48 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,000

Rep: Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003
the command last will give you info about the reboots.
From the other hand there is a command uptime.
 
1 members found this post helpful.
Old 09-28-2012, 12:50 AM   #3
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,435
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
The command uptime will show you how long your system is up.
But I guess what you want to know is an overall uptime. Like 10mins up -> reboot -> 2days up -> reboot -> 3weeks up. To a total of 3weeks 2days and 10minutes. Right? Sorry but that is not possible with build in tools. You have to "manually" do the math and save this between reboots or similar. There are some threads here on LQ how to do this.
 
Old 09-28-2012, 01:05 AM   #4
manoj.linux
Member
 
Registered: Aug 2007
Posts: 219

Original Poster
Rep: Reputation: 15
Thanks Zhjim for your quick response.
 
Old 09-28-2012, 01:12 AM   #5
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,435
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
Pan64 thanks for bringing up the last command. What I just found out is that the output lines of last with reboot on them also show you the time from when to when the system was up.

I learned something during my first cup of coffee. Must be a good day
 
Old 09-28-2012, 01:31 AM   #6
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,435
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
Little script to compute overall uptime

Code:
#!/bin/bash
while read line; do
# *edit start*
        # clear last run data
        day=0
        hour=0
        minute=0

        # if there are days we have more than 5 characters
        # hour:minute
        if [ ${#line} -gt 5 ]; then
                day=$(echo $line | cut -d '+' -f 1)
                line=$(echo $line | cut -d '+' -f 2)
        fi
# *edit stop*
	#remove leading zero to not go octal
	hour=$(echo $line| cut -d ":" -f 1 | sed 's/^0//') 
	minute=$(echo $line | cut -d ":" -f 2| sed 's/^0//')
 
	#sum things up
# *edit start*
        if [ $day -gt 0 ]; then
                DAY=$(($DAY+ $day))
        fi
# *edit stop*
	if [ $hour -gt 0 ]; then
		HOUR=$(($HOUR + $hour))
	fi
	if [ $minute -gt 0 ]; then
		MIN=$(($MIN + $minute))
	fi
done < <(last | grep reboot | awk '{print $11}'| tr -d "(" | tr -d ")") 
# 60 minutes per hour?
UP=$(($MIN / 60))
MIN=$(($MIN % 60 ))
HOUR=$(($HOUR + $UP))

# *edit start*
# 24 hours per day?
UP=$(($HOUR / 24))
HOUR=$(($HOUR % 24))
DAY=$(($DAY + $UP))
# *edit stop*


#echo "Overall uptime of $HOUR hours and $MIN minutes"
echo "Overall uptime of $DAY days, $HOUR hours and $MIN minutes"

Last edited by zhjim; 09-28-2012 at 08:08 AM.
 
Old 09-28-2012, 07:18 AM   #7
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Slack14_64_Multilib
Posts: 2,723
Blog Entries: 3

Rep: Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627
"last reboot" and "uptime" are good, but here's an alternative that I occassionally use now to find the 'uptime' of an individual process. (This process just happens to be init).

Code:
ps -p $(pidof -x init) -o lstart
                 STARTED
Tue Sep 25 08:52:20 2012
Useful? Maybe.

Credit goes to fernfrancis...
 
Old 09-28-2012, 07:41 AM   #8
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,435
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
Whuhu. last reboot is even better. Running on a server I also saw that I don't have days in my script. Editing in progress.

Last edited by zhjim; 09-28-2012 at 08:04 AM.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
init uptime longer than system uptime? m4rtin Linux - Server 1 09-15-2010 07:45 AM
Finding out interface uptime GSMD Linux - Networking 4 12-13-2007 04:06 PM
uptime for server einstien Linux - General 2 09-20-2004 08:35 PM
Server uptime discrepancy peppiv Linux - Software 2 05-17-2004 11:41 AM
Remote Server Uptime duerra Linux - General 6 05-12-2004 05:50 PM


All times are GMT -5. The time now is 01:17 PM.

Main Menu
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