Tag Info

uptime
If you want it in numerical form, it's the first number in /proc/uptime (in seconds), so the time of the last reboot is
date -d "$(</proc/uptime awk '{print $1}') seconds ago"
The uptime includes the time spent in a low-power state (standby, suspension or hibernation).

Load is not equal to CPU usage. It is basically an indicator how many processes are waiting to be executed.
Some helpful links:
http://superuser.com/questions/23498/what-does-load-average-mean-in-unix-linux
http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages

If you have a separate server to run your check script on, something like this would do a simple Ping test to see if the server is alive:
#!/bin/bash
SERVERIP=192.168.2.3
NOTIFYEMAIL=test@example.com
ping -c 3 $SERVERIP > /dev/null 2>&1
if [ $? -ne 0 ]
then
# Use your favorite mailer here:
mailx -s "Server $SERVERIP is down" -t ...

In general, on a RPM-based distribution like Fedora, you can find the name of the package which provides a given command with rpm -qf /path/to/command. Like this:
$ rpm -qf $( which uptime )
procps-3.2.8-18.20110302git.fc16.x86_64
You can then download the source RPM with yumdownloader --source procps. (yumdownloader comes from the yum-utils package, if ...

Uptime is part of the 'procps' package, the upstream source is at http://procps.sourceforge.net/ (Not a fedora user, so not sure where to find their .src.rpm).
To answer the question you didn't ask, however; take a look in /proc/uptime
The first number is seconds since boot. You should be able to turn that into something usable fairly easily :)

As log-files are usually deleted after some time, the total up-time is difficult to get.
If the hard disk is as old as the PC, the RAW value (last number) of
smartctl -a /dev/sda | grep Power_On_Hours
could give a rough estimate how many hours the PC was used.

Pinging is an option, but on many occasions a machine will be able to send a ping reply, while the actual server that it is all about is down. It is better do an end-to-end test. In the below example a page is requested from the webserver.
If it is a webserver, it would look something like this:
#!/bin/bash
wget -qO /dev/null ...

You can use uptime or last
To see only the last time
last reboot -F | head -1 | awk '{print $5,$6,$7,$8,$9}'
more generically
last reboot
Note and warning
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.

Load average is the number of processes who are in waiting queue for CPU time. These three values are the average number of processes in waiting queue for past 1, 5 and 15 minutes.
I would suggest you to read the following articles:
Linux Troubleshooting, Part I: High Load
Examining Load Average
I personally believes more on CPU IDLE Time than on load ...

The output of uptime depends on the uptime itself, i.e.
On one system
$ uptime
17:35pm up 5 days 9:24, 9 users, load average: 0.30, 0.28, 0.28
thus, 12 fields.
On another system
uptime
17:36:15 up 8:44, 2 users, load average: 0.09, 0.30, 0.41
And thus 10 fields. It may defer for your system, of course. I suppose that you switched on your ...

uptimed
One such tool that I came across many years ago is called uptimed. The project site is here: http://podgorny.cz/moin/Uptimed.
This is a pretty straightforward install, given uptimed appears to be in most of the major distros' repositories.
Installation
$ sudo yum install uptimed
Once installed the service needs to be configured so that it will ...

You can use the following 2 commands (who & last) to find out the last time the system was rebooted and also messages about previous shutdown or runlevel changes.
Last time system booted?
For this you can use the who command. Specifically with the -b switch.
$ who -b
system boot 2013-08-01 17:56
This says the last time the system was ...

If you have some server, use commands like:
uptime
w
last
HDD SMARTCTL is also good try.
Also from installation could be information about date created of some files in filesystem. Think about, which files were created with installing of your system?
If you have linux, look at the date of creation of your /root/ directory.
If you have windows, it ...

On any POSIX-compliant system, you can use the etime column of ps.
LC_ALL=POSIX ps -o etime= $PID
The output is broken down into days, hours, minutes and seconds with the syntax [[dd-]hh:]mm:ss. You can work it back into a number of seconds with simple arithmetic:
t=$(LC_ALL=POSIX ps -o etime= $PID)
d=0 h=0
case $t in *-*) d=${t%%-*}; t=${t#*-};; esac
...

You can do this for example with perl and some simple math:
cat /proc/uptime | perl -ne '/(\d*)/ ; printf "%02d:%02d:%02d:%02d\n",int($1/86400),int(($1%86400)/3600),int(($1%3600)/60),$1%60'
If you do not need the seconds, you can simply run the uptime command. Its output can then be simply transformed to DD:HH:MM.
For example using (works this way only ...

No, because it's not really a hard problem. Divide the number of seconds by 86400 using integer division to get the number of days. Take the remainder and divide that by 3600 to get the number of hours. Divide the remainder of that by 60 to get the number of minutes, and you're left with the number of seconds. All this is doable from the shell using the ...

I usually use who -b, which produces output such as:
$ who -b
system boot 2014-05-06 22:47
$
It tells me the date and time when the machine was last booted, rather than the time that has elapsed since it was last booted.
This command works on many other Unix systems too (Solaris, …).

First of all, crtime is tricky on Linux. That said, running something like
$ stat -c %z /proc/
2014-10-30 14:00:03.012000000 +0100
or
$ stat -c %Z /proc/
1414674003
is probably exactly what you need. The /proc file system is defined by the LFS standard and should be there for any Linux system as well as for most (all?) UNIXen.
Alternatively, ...

The first field of /proc/uptime is your friend for when (go read it with cat /proc/uptime). It's a running count of seconds that your system has been up. The second field of that file is how many cpuseconds have been idle on your system (divide it by the number of CPUs listed in /proc/cpuinfo in that system to get actual seconds).
# if your awk is new ...

For scripting purposes I find it easier to get the load averages directly from /proc/loadavg then to try and parse uptime's annoying output.
Example
$ cat /proc/loadavg
1.08 0.77 0.85 2/838 16771
From man proc:
/proc/loadavg
The first three fields in this file are load average figures
giving the number of jobs in the run queue (state ...

uptime shows system load (not exactly CPU usage), which is described in man uptime as follows:
System load averages is the average number of processes that are
either in a runnable or uninterruptable state. A process in a runnable
state is either using the CPU or waiting to use the CPU. A process in
uninterruptable state is waiting for some I/O ...

The uptime command reads the two values out of /proc/uptime, actually. The first value is the amount of time since the machine booted. The second value, however, is the sum of time that each cpu has had had a runnable process to schedule.
If you have a copy of the kernel source around, check out fs/proc/uptime.c and you'll see how the /proc/uptime file's ...

the machine is remote/embed in a system.Sometimes the electricity is shut down. The internet connection is very slow
Does the system have a clock and a battery in it?1 A lot of embedded systems don't. If not, this:
Some other answers would say that the ntp server was launched after the reboot and so the system had to go backwards to set the ...

/var/log/messages
That is the main log file you should check for messages related to this. Additionally either /var/log/syslog (Ubuntu) or /var/log/secure (CentOS)
To find out when your server was last rebooted just type uptime to see how long it has been up.

If you are using Ubuntu
then add below lines in "/etc/rc0.d/S60umountroot" at the beginning.
Log="/var/log/uptime.log"
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 ...