Bash command not found

i have found this flow, which scan a network, the output is just empty so i added a second msg.payload where i got a error
/bin/bash: sudo: command not found

my node Red is in a Containers on my pi itself it would work

[{"id":"c3961d41.0f858","type":"tab","label":"Scan Subnet for Devices","disabled":false,"info":""},{"id":"842fa7ed.314678","type":"inject","z":"c3961d41.0f858","name":"","props":[{"p":"payload","v":"","vt":"date"},{"p":"topic","v":"","vt":"string"}],"repeat":"60","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":60,"wires":[["c43bcf07.4070d"]]},{"id":"c43bcf07.4070d","type":"exec","z":"c3961d41.0f858","command":"sudo nmap -sn | awk '/Nmap scan report for/{printf $5;}/MAC Address:/{print \"|\"substr($0, index($0,$3)) }' | sort","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"scan subnet","x":370,"y":60,"wires":[["6903a852.c6bd58"],["65f5cef1.0da3c"],[]]},{"id":"6903a852.c6bd58","type":"function","z":"c3961d41.0f858","name":"Subnet Devices Array","func":"let response = msg.payload.split('\\n');\nlet found = []\nlet device\nresponse.forEach ( line => {\n    if ( line.indexOf('|') > -1 ){\n        device = {\n            ip : line.split('|   ')[0],\n            mac: line.split('|')[1].split(' ')[0],\n            brand: line.split('|')[1].split(' ')[1]\n        }\n        found.push ( device )\n    }\n})\nmsg.payload = found;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":60,"wires":[["c5c606d2.36a7f8"]]},{"id":"c5c606d2.36a7f8","type":"debug","z":"c3961d41.0f858","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":60,"wires":[]},{"id":"65f5cef1.0da3c","type":"debug","z":"c3961d41.0f858","name":"test Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":220,"wires":[]}]

What does a debug node connected to the Exec node show?

I see the exec node runs that command. If you run it in a terminal does it work and do you need to enter a password?

unless you have sudo and nmap installed inside your container then it is always going to fail.
(and indeed the whole point of containers is to stop people running system level commands that could damage the rest of the system) - so either you need to install them inside your container (which even then would only scan the network inside the container) - or give it extra privileges to see out of the container. But realistically if you are trying to run things like nmap then you don't want to do it from within a container.

1 Like

yes you are correct - this is the problem there is no nmap or Sudo insight the container.
Would have been a nice way to check the network for new device

have a nice day

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.