napajedlaci.cz
Posts: 98
Joined: Mon Apr 13, 2015 1:13 am

Download data from URL and save to /dev/stdout

Fri Oct 19, 2018 7:42 am

Hello,
I need to create script for Raspberry PI, which will be able to retrieve the data from the URL and secure this load against potential outages.

I need to print the loaded data and send it to /dev/stdout

Will someone please help me? :oops:

napajedlaci.cz
Posts: 98
Joined: Mon Apr 13, 2015 1:13 am

Re: Download data from URL and save to /dev/stdout

Fri Oct 19, 2018 8:09 am

Code: Select all

data="`wget -q O- http://www.example.com/linux_data.php'`"
This code is safe, ok?

Now I need to send data, save to /dev/stdout
Unfortunately, I do not know.


n67
Posts: 839
Joined: Mon Oct 30, 2017 4:55 pm

Re: Download data from URL and save to /dev/stdout

Fri Oct 19, 2018 10:51 am

Note that -O- also works (with wget). Yes, the space (before the -) is optional in this case.

I think that's the more common/standard way to do it (and is less typing).
"L'enfer, c'est les autres"

If a post offends you, just put that poster on your foes list, and be done with it (and with them).

To do otherwise, risks being banned.

User avatar
Paeryn
Posts: 2169
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Download data from URL and save to /dev/stdout

Fri Oct 19, 2018 11:04 am

Heater and n67 beat me to posting, but just in case you are needing the data in a shell variable (as per your example) as well as printing it...
napajedlaci.cz wrote:
Fri Oct 19, 2018 8:09 am

Code: Select all

data="`wget -q O- http://www.example.com/linux_data.php'`"
This code is safe, ok?

Now I need to send data, save to /dev/stdout
Unfortunately, I do not know.
You are missing a hyphen before O- and have a lone single quote ' at the end. I'd write it in the more modern way

Code: Select all

data=$(wget -q -O- http://www.example.com/linux_data.php)
To write this to the current shell scripts' stdout at any point just do

Code: Select all

echo $data
afterwards. As to sending data somewhere, that all depends on where you are sending it and how you are wanting to send it.
She who travels light — forgot something.

Return to “C/C++”