If found this code
JavaScript
x
host raspberrypi | grep 'address' | cut -d' ' -f4
which gives pi Ip address
and this
JavaScript
wget --post-data="PiIP=1.2.3.4" http://dweet.io/dweet/for/cycy42
which sends 1.2.3.4 off to dweet.io stream
How can I get the output from 1st to replace the 1.2.3.4 in second please?
Advertisement
Answer
Save the output of the first command in a variable:
JavaScript
ip=$(host raspberrypi | grep 'address' | cut -d' ' -f4)
wget --post-data="PiIP=$ip" http://dweet.io/dweet/for/cycy42
Btw, if your raspberrypi is running raspbian, then a much cleaner way to get the IP address:
JavaScript
hostname -I
Simplifying the commands to:
JavaScript
ip=$(hostname -I)
wget --post-data="PiIP=$ip" http://dweet.io/dweet/for/cycy42
Making that a one-liner:
JavaScript
wget --post-data="PiIP=$(hostname -I)" http://dweet.io/dweet/for/cycy42
UPDATE
So it seems hostname -I
gives a bit different output for you.
You can use this then:
JavaScript
ip=$(hostname -I | awk '{print $1}')
To make it a one-liner, you can insert this into the second line just like I did in the earlier example.