I am running Raspbian on a Raspberry PI Model B 24/7
How would I post Uptime automatically to a website?
I am running Raspbian on a Raspberry PI Model B 24/7
How would I post Uptime automatically to a website?
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.05The 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.
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 ??
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
Of course you need to make sure proper formatting is around that (e.g. a or ), 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.
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 "s/*/${UPTIME}/"
change to the proper line number to edit
put that into crontab
with php you can use
greetings Chrigu
>
what sort of website, and where?
-- Ineptocracy
(in-ep-toc?-ra-cy) ? a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
It is hosted on Daily - daily.co.uk and would simply be an HTML file displaying
My Raspberry Pi Has Been Up And Running For
As I said I know how to get the value UPTIME and I know how to get this file to the website via FTP - just not able to figure out how to display it on the page
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.
^thought into
Here's a very basic way to do it with two text files and a short script:
uptime1.txt:
-----------------------------
My Raspberry Pi has been up for
------------------------------
uptime2.txt:
-------------------------------
-------------------------------
uptime.sh:
------------------------------- #!/bin/bash cat uptime1.txt > uptime.html uptime | cut -d 'p' -f2 | cut -d ',' -f1 >> uptime.html cat uptime2.txt >> uptime.html
-------------------------------
Then make the script executable chmod u+x uptime.sh and run the script and the FTP upload from chron every ten minutes, hour or whatever. When you FTP the HTML file make sure it overwrites the existing one.
Thanks for all the replies - I will work through them to find one that works/suits my needs :)
With no PHP or SSI on the server end you could still use some client-side Javascript to embed one file in another.
Theo
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.
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.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 alan@adamshome.org.uk http://www.nckc.org.uk/
On Mon, 07 Jul 2014 13:33:51 +0100, Tardis Designer declaimed the following:
So why upload a text file... Why not just upload the whole HTML with the current time value already in place.
Or go through the effort of generating a GIF/PNG image file containing the uptime and uploading that... The HTML would then have a suitable tag to make the browser fetch the image file directly.
-- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Use some scripting (I'd use sed or an awk script) to edit the uptime into a master HTML page that's kept on the RPi. Use either ftp or scp to upload the page to the web server. Wrap the both up in a cron job configured to execute however often you want.
ftp is easy enough to script by using a 'here' document (see the bash manpage for details) and scp is a command line utility for doing file transfers: if the web server supports ssh (and most do nowadays) then using scp to do the transfer is a no-brainer.
-- martin@ | Martin Gregorie gregorie. | Essex, UK org |
totally off topic, but
iframe is probably the easiest way:
but you may wan to look at other newer elements like embed and object.
else you could fetch it using AJAX,
-- umop apisdn
SSI isn't html. it's a server extension, like PHP.
-- umop apisdn
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.
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.