How to get IP from bash command

I'm trying to get the ip-adres of the raspberry pi which my node-red server is running on (it has Rhasspy running on it too, so I'll be able to ask for it, but that is not the issue).
I use this bash-command:
/sbin/ip -4 -o addr show dev eth0| /usr/bin/awk '{split($4,a,"/");print a[1]}'

which runs fine in the linux-terminal
However when I put it in an exec-node in node-red, it no longer works.
This is my flow:

ty[{"id":"aa7ebe61.f0a9f","type":"tab","label":"WhatsMyIp","disabled":false,"info":""},{"id":"507071fb.dfcf78","type":"debug","z":"aa7ebe61.f0a9f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":120,"wires":[]},{"id":"4c8ca89e.31f138","type":"exec","z":"aa7ebe61.f0a9f","command":"/sbin/ip -4 -o addr show dev eth0| /usr/bin/awk '{split($4,a,\"/\");print a[1]}'","addpay":true,"append":"","useSpawn":"false","timer":"20","oldrc":false,"name":"GetIp","x":310,"y":160,"wires":[["507071fb.dfcf78"],["988934e3.be1e48"],["a82d10e4.9c853"]]},{"id":"988934e3.be1e48","type":"debug","z":"aa7ebe61.f0a9f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":160,"wires":[]},{"id":"a82d10e4.9c853","type":"debug","z":"aa7ebe61.f0a9f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":200,"wires":[]},{"id":"db06641a.216ec8","type":"inject","z":"aa7ebe61.f0a9f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":260,"wires":[["4c8ca89e.31f138"]]}]pe or paste code here

I resorted to this approach because the node-red-contrib-get-my-ip fails to install.

kind regards,
Hugo

you need to untick the append msg.payload option...

Couldn’t you also just use hostname -I in the exec node instead?

Johannes

I tried it and it installs fine with the Manage palette menu option. Works well, too, but I deleted it because the doc is non-existent and I don't trust it.

That has to be a lowercase "-i" on my systems, which are Arch Linux. In my case it just returns "127.0.0.1 127.0.0.1" which is probably not what @hugocoolens wants.

Works on raspberry pi os and is actually also in their documentation.
The first one returned is the ip for me on all my pis.

you need to untick the append msg.payload option...

Thanks for this suggestion. Now I get an ip-adress, the strange thing is however, it is not the same one as the one I get when giving the same command in a linux-shell on the raspberry. Could this behaviour be caused by the fact I am running node-red in a docker-container?

kind regards,
hugo

Yes you will get the internal ip of the container

hostname -I (uppercase) gives me 5 !!! ip-addresses.
Any idea where those are coming from?

kind regards,
hugo

From the networking layer :-). Docker sets up several. Plus the host, etc.

Yes you will get the internal ip of the container

Any idea how to get the one from the raspberry itself using this command?

kind regards,
Hugo

The whole point of containers is to be isolated from their hosts. Simplest is don’t run in a container. But if you are browsing to node-red presumably you know it anyway ?