<p>How can I get a history of uptimes for my debian box? After a reboot, I dont see an option for the uptime command to print a history of uptimes. If it matters, I would like to use these uptimes for graphing a page in php to show my webservers uptime lengths between boots.</p>

<p>Update: 
Not sure if it is based on a length of time or if last gets reset on reboot but I only get the most recent boot timestamp with the last command. last -x also does not return any further info.  Sounds like a script is my best bet.</p>

<p>Update:
Uptimed is the information I am looking for, not sure how to grep that info in code. Managing my own script for a db sounds like the best fit for an application.</p>

[{'answer_id': 79503, 'author': 'John Boker', 'author_id': 2847, 'author_profile': 'https://Stackoverflow.com/users/2847', 'pm_score': 1, 'selected': False, 'text': '<p>i dont think this information is saved between reboots.</p>\n\n<p>if shutting down properly you could run a command on shutdown that saves the uptime, that way you could read it back after booting back up.</p>\n'}, {'answer_id': 79515, 'author': 'roo', 'author_id': 716, 'author_profile': 'https://Stackoverflow.com/users/716', 'pm_score': 5, 'selected': False, 'text': '<p>the <a href="http://linux.about.com/library/cmd/blcmdl1_last.htm" rel="noreferrer"><code>last</code></a> command will give you the reboot times of the system. You could take the difference between each successive reboot and that should give the uptime of the machine.</p>\n\n<p><strong>update</strong></p>\n\n<p><a href="https://stackoverflow.com/questions/79490/linux-uptime-history#79553">1800 INFORMATION</a> answer is a better solution.</p>\n'}, {'answer_id': 79530, 'author': 'Kyle Cronin', 'author_id': 658, 'author_profile': 'https://Stackoverflow.com/users/658', 'pm_score': 1, 'selected': False, 'text': '<p>This information is not normally saved. However, you can sign up for an online service that will do this for you. You just install a client that will send your uptime to the server every 5 minutes and the site will present you with a graph of your uptimes:</p>\n\n<p><a href="http://uptimes-project.org/" rel="nofollow noreferrer">http://uptimes-project.org/</a></p>\n'}, {'answer_id': 79535, 'author': 'Shermozle', 'author_id': 10788, 'author_profile': 'https://Stackoverflow.com/users/10788', 'pm_score': 2, 'selected': False, 'text': '<p>This isn\'t stored between boots, but <a href="http://www.uptimes-project.org" rel="nofollow noreferrer">The Uptimes Project</a> is a third-party option to track it, with software for a range of platforms.</p>\n\n<p>Another tool available on Debian is <a href="http://podgorny.cz/moin/Uptimed" rel="nofollow noreferrer">uptimed</a> which tracks uptimes between boots.</p>\n'}, {'answer_id': 79540, 'author': 'etchasketch', 'author_id': 14640, 'author_profile': 'https://Stackoverflow.com/users/14640', 'pm_score': 6, 'selected': True, 'text': '<p>You could create a simple script which runs uptime and dumps it to a file.</p>\n\n<pre><code>uptime &gt;&gt; uptime.log\n</code></pre>\n\n<p>Then set up a cron job for it.</p>\n'}, {'answer_id': 79553, 'author': '1800 INFORMATION', 'author_id': 3146, 'author_profile': 'https://Stackoverflow.com/users/3146', 'pm_score': 6, 'selected': False, 'text': '<p>Install <a href="https://github.com/rpodgorny/uptimed" rel="nofollow noreferrer">uptimed</a>. It does exactly what you want.</p>\n\n<p>Edit:</p>\n\n<p>You can apparantly include it in a PHP page as easily as this:</p>\n\n<pre><code>&lt;? system("/usr/local/bin/uprecords -a -B"); ?&gt;\n</code></pre>\n\n<p><a href="https://web.archive.org/web/20090228064718/http://www.robertjohnkaper.com/software/uptimed/example.html" rel="nofollow noreferrer">Examples</a></p>\n'}, {'answer_id': 79699, 'author': 'paxdiablo', 'author_id': 14860, 'author_profile': 'https://Stackoverflow.com/users/14860', 'pm_score': 2, 'selected': False, 'text': "<p>I would create a cron job to run at the required resolution (say 10 minutes) by entering the following [on <em>one</em> single line - I've just separated it for formatting purposes] in your crontab (cron -l to list, cron -e to edit).</p>\n\n<pre><code>0,10,20,30,40,50 * * * *\n    /bin/echo $(/bin/date +\\%Y-\\%m-\\%d) $(/usr/bin/uptime)\n    &gt;&gt;/tmp/uptime.hist 2&gt;&amp;1\n</code></pre>\n\n<p>This appends the date, time and uptime to the uptime.hist file every ten minutes while the machine is running. You can then examine this file manually to figure out the information or write a script to process it as you see fit.</p>\n\n<p>Whenever the uptime reduces, there's been a reboot since the previous record. When there are large gaps between lines (i.e., more than the expected ten minutes), the machine's been down during that time.</p>\n"}, {'answer_id': 80135, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>Try this out:    </p>\n\n<pre><code>last | grep reboot \n</code></pre>\n'}, {'answer_id': 6330117, 'author': 'Slet', 'author_id': 792504, 'author_profile': 'https://Stackoverflow.com/users/792504', 'pm_score': 1, 'selected': False, 'text': '<p>Or you can use tuptime <a href="https://sourceforge.net/projects/tuptime/" rel="nofollow">https://sourceforge.net/projects/tuptime/</a> for a total uptime time.</p>\n'}, {'answer_id': 18943901, 'author': 'sepehr', 'author_id': 184176, 'author_profile': 'https://Stackoverflow.com/users/184176', 'pm_score': 4, 'selected': False, 'text': '<p>according to <code>last</code> manual page:</p>\n\n<blockquote>\n  <p>The pseudo user reboot logs in each time the system  is  rebooted.\n         Thus last reboot will show a log of all reboots since the log file\n         was created.</p>\n</blockquote>\n\n<p>so last column of <code>#last reboot</code> command gives you uptime history:</p>\n\n<pre><code>#last reboot\nreboot   system boot  **************** Sat Sep 21 03:31 - 08:27 (1+04:56)   \nreboot   system boot  **************** Wed Aug  7 07:08 - 08:27 (46+01:19)\n</code></pre>\n'}, {'answer_id': 20195042, 'author': 'peterh', 'author_id': 1783163, 'author_profile': 'https://Stackoverflow.com/users/1783163', 'pm_score': 0, 'selected': False, 'text': '<p>Nagios can make even very beautiful diagrams about this.</p>\n'}, {'answer_id': 23121600, 'author': 'rfmoz', 'author_id': 793908, 'author_profile': 'https://Stackoverflow.com/users/793908', 'pm_score': 1, 'selected': False, 'text': '<p>You can use tuptime, a simple command for report the total uptime in linux keeping it betwwen reboots.</p>\n\n<p><a href="http://sourceforge.net/projects/tuptime/" rel="nofollow">http://sourceforge.net/projects/tuptime/</a></p>\n'}, {'answer_id': 55663620, 'author': 'Jan Schermer', 'author_id': 11355087, 'author_profile': 'https://Stackoverflow.com/users/11355087', 'pm_score': 1, 'selected': False, 'text': '<p>Since I haven\'t found an answer here that would help retroactively, maybe this will help someone.</p>\n\n<p>kern.log (depending on your distribution) should log a timestamp.\nIt will be something like:\n2019-01-28T06:25:25.459477+00:00 someserver kernel: [44114473.614361] somemessage</p>\n\n<p>"44114473.614361" represents seconds since last boot, from that you can calculate the uptime without having to install anything.</p>\n'}, {'answer_id': 62146140, 'author': 'sebisnow', 'author_id': 6207983, 'author_profile': 'https://Stackoverflow.com/users/6207983', 'pm_score': 0, 'selected': False, 'text': '<h1>Use Syslog</h1>\n\n<p>For anyone coming here searching for their past uptime.\nThe solution of @1800_Information is a good advise for the future, but I needed to find information for my past uptimes on a specific date.</p>\n\n<p>Therefore I used syslog to determine when that day the system was started (first log entry of that day) and when the system was shutdown again.</p>\n\n<h2>Boot time</h2>\n\n<p>To get the system start time grep for the month and day and show only the first lines:</p>\n\n<pre><code>sudo grep "May 28" /var/log/syslog* | head\n</code></pre>\n\n<h2>Shutdown time</h2>\n\n<p>To get the system shutdown time grep for the month and day and show only the last few lines:</p>\n\n<pre><code>sudo grep "May 28" /var/log/syslog* | tail\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/79490', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/777/']