Page 1 of 1

Download data from URL and save to /dev/stdout

Posted: Fri Oct 19, 2018 7:42 am
by napajedlaci.cz
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:

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

Posted: Fri Oct 19, 2018 8:09 am
by napajedlaci.cz

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.

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

Posted: Fri Oct 19, 2018 10:48 am
by Heater
$ wget -q -O /dev/stdout https://www.raspberrypi.org/forums

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

Posted: Fri Oct 19, 2018 10:51 am
by n67
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).

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

Posted: Fri Oct 19, 2018 11:04 am
by Paeryn
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.