Post Uptime

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I am running Raspbian on a Raspberry PI Model B 24/7

How would I post Uptime automatically to a website?

Re: Post Uptime
On 07/07/14 10:20, Tardis Designer wrote:
Quoted text here. Click to load it

Is this a website running on the Pi itself, or on another box?

To get the uptime, you can parse the output of the "uptime" command

10:46:29 up 144 days, 14:22,  3 users,  load average: 0.00, 0.01, 0.05

The first part is the current time, the bit after "up" is how long the  
system has been running, the "n users" etc, you can ignore the rest.

Or you could use
cut -d' ' -f1 /proc/uptime
which will give you the uptime in seconds.

If the website is runnign on the Pi, then a simple php script could do that.

If on another system, you'd need to generate a web page and upload it to  
that site, depending on how the hosting provider allows uploads.

Re: Post Uptime
On 07/07/2014 10:52, Dom wrote:
Quoted text here. Click to load it

The Website would be on a remote site
This is as far as I have got

uptime > uptime.txt

Then use ncftpput to upload it to the remote site

How do I make it display on the remote site. ie what is the HTML code  
that will embed and display uptime.txt ??

Re: Post Uptime
Quoted text here. Click to load it

Of course that depends on the technology you use (or are allowed to
use) on the remote website.

When only HTML you need to have SSI to "include" the file into the HTML
using <!-- #include file="uptime.txt" -->

Of course you need to make sure proper formatting is around that
(e.g. a <p> or <pre>), and you may want to use a full pathname for
the file when it is not in the same directory as the html document.

When you have no SSI, it is tougher.

Re: Post Uptime
Am 07.07.2014 13:25, schrieb Rob:
Quoted text here. Click to load it
with php you can use

<?php readfile("uptime.txt"); ?>

greetings
Chrigu
Quoted text here. Click to load it


Re: Post Uptime
Quoted text here. Click to load it

Yes, with PHP.   But he said he had HTML.
Often PHP is not available on simple homepage services, and if it is,
there has often not gone enough design of the site to make it easy to go
from .html to .php without breaking all the (internal and external) links.

Re: Post Uptime
Quoted text here. Click to load it
                                 ^thought into
Quoted text here. Click to load it

Re: Post Uptime
Quoted text here. Click to load it

That's easy enough to work around - leave a redirection page in
the original location referring to the PHP file.

The other way that comes to mind would be to invert the problem -
instead of reporting the uptime report the time the system was
booted.   It'd be easy enough to place the output of "who -b" into
the HTML locally and upload it to the web server as an init script.

--  
Andrew Smallshaw
snipped-for-privacy@sdf.lonestar.org

Re: Post Uptime
Quoted text here. Click to load it

that can't be trusted as evidence of uptime unless it's the same
sytem that's running the webserver.

my raspberry pi would be showing 4 weeks uptime by that measure but
it's been powered down for 2 weeks,

--  
umop apisdn


Re: Post Uptime
Quoted text here. Click to load it

The same is true of the uptime: sure if it says up 1 year+ it's
proof that it was up at some point for at least that long but says
nothing if it has subsequently been powered down since.  The
assumption for anything updated periodically is that it is an
always-on system or at least some kind of time-out applies if you
haven't heard anything for a while.  If those limitations are not
acceptable you need some form of real-time data acquisition, e.g.
as at http://andrews.freeshell.org/news/20140717.csr/ping.txt which
was in use for my home network for a while - I wouldn't recommend
Bourne shell for CGI scripts on the public-facing Internet but it
worked well enough for me.

--  
Andrew Smallshaw
snipped-for-privacy@sdf.lonestar.org

Re: Post Uptime
Quoted text here. Click to load it

Surely the easiest "fix" is to use something like the output of

#!/sh
echo "RPi uptime:"
uptime
echo "Page last updated:"
date

Then if your RPi falls off the net for any reason, visitors to the site
can see how fresh/stale the uptime (or boot time) data is.

For bonus points, you could return the data in a form which is parsable
by whatver javascript/php/etc you're using on the web server end - and
have the page report "no update in 5 days, is the pi down?"

-Paul
--  
http://paulseward.com

Re: Post Uptime
Quoted text here. Click to load it

With no PHP or SSI on the server end you could still use some client-side
Javascript to embed one file in another.

Theo

Re: Post Uptime
On Mon, 07 Jul 2014 12:49:03 +0000, Rob wrote:

Quoted text here. Click to load it

IIRC when a web server just returns text, not wrapped by any HTML, a  
browser will just display it.  I'll get my local server up and try this.

Yeah.  Works with firefox.  I saved the uptime result in uptime.txt, then  
(with a simple server running) went to firefox and asked for
http://localhost:8000/uptime.txt
Lo and behold ...


    Mel.

Re: Post Uptime

Quoted text here. Click to load it






True enough. The problem comes when you want to include the uptime  
information in an existing page.

That has several possible solutions:

1  include the information using php, which forms part of the page,  
e.g.

<pre>
<?php
include 'file.txt'
?>
</pre>

2  Edit the page file on the web server - likely to be tricky, or run  
into permissions issues

3  Create a new copy of the page file, and upload it, replacing the  
existing page. This might be done be downloading the page, editing it,  
then uploading it again. Doing that with a script would need a  
reliable way to find the bit that needed editing.

Various other techniques would be possible, but it would need more  
information about what the web server supports by way of scripts, what  
restrictions are placed on ftp up- and downloads etc.

--  
Alan Adams, from Northamptonshire
snipped-for-privacy@adamshome.org.uk
We've slightly trimmed the long signature. Click to see the full one.
Re: Post Uptime
In comp.sys.raspberry-pi message < snipped-for-privacy@iyonix.adamshom
posted:

Quoted text here. Click to load it


I think it is standard to be able to put a hidden <iframe> in a Web
page, loading it with same-source plain-text or HTML, and then read that
material with JavaScript and write some or all of it into the visible
Web page.  I've not done all of that in one Web page; but I have done
all of the parts in different pages.  That should require only that the
web server can serve text or HTML, but may well not work in Chrome from
a local disc without using a server (over-zealous security).


--  
 (c) John Stockton, nr London, UK.  For Mail, see Home Page.  Turnpike, WinXP.
 Web  <http://www.merlyn.demon.co.uk/ - FAQ-type topics, acronyms, and links.
We've slightly trimmed the long signature. Click to see the full one.
Re: Post Uptime

Quoted text here. Click to load it

If it's on the same server as the main page and script you can read the  
content of the file directly in javascript using XmlHttpRequest()

--  
umop apisdn


Re: Post Uptime
Quoted text here. Click to load it

SSI isn't html.  it's a server extension, like PHP.


--  
umop apisdn


Re: Post Uptime
Quoted text here. Click to load it

Of course, but it existed long before PHP, and some of those ancient
servers sometimes installed to let home internet subscribers publish
a HTML page provide SSI but not PHP.

Re: Post Uptime

Quoted text here. Click to load it

totally off topic, but

iframe is probably the easiest way:

 <iframe style="width:50em;height:3ex" src="uptime.txt" />

but you may wan to look at other newer elements like embed and object.

else you could fetch it using AJAX,

<iframe style="width:50em;height:3ex" src="uptime.txt" />

--  
umop apisdn


Re: Post Uptime
Dom wrote:

Quoted text here. Click to load it

Create an html document, then create a bash script that takes the  
information you posted, then using sed updates the html file.
Something like this:

#!/bin/bash
UPTIME=$(uptime)
sed -e "<line number>s/*/$/"



change <line number> to the proper line number to edit

put that into crontab


Site Timeline