A great man recently said
Part of our thinking was that [Node-red] would never be perfect for everyone ... and ... by having flexibility like the function node, or jsonata ... we might encourage people to take some steps towards programming
In this admirable spirit of permitting other programming languages within a Node-red flow, I've been trying to use another scripting language - awk. It does work, but it's ugly and fragile - it breaks if msg.payload includes the single quote character.
[{"id":"592ffdee5f873981","type":"group","z":"909b559e8da63ab3","name":"Pass both data and code to Bash","style":{"label":true},"nodes":["4b1f05c457207ae7","651a384bfd552f20","1a2253e8bccbf044","24b6092031129039","40de53dbd53a8a68","6b30c9d1264f0ab6","0e47b3a6a310d146","dce992b473605617","1e226f7cee4efb99"],"x":314,"y":31.5,"w":692,"h":209.5},{"id":"4b1f05c457207ae7","type":"exec","z":"909b559e8da63ab3","g":"592ffdee5f873981","command":"echo '","addpay":"payload","append":"' | awk -v FS=\"[:,]\" '{ printf \"%f%%\\n\", (100 * ($2 - $6) / $2) }'","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":770,"y":80,"wires":[["651a384bfd552f20"],["651a384bfd552f20"],[]]},{"id":"651a384bfd552f20","type":"debug","z":"909b559e8da63ab3","g":"592ffdee5f873981","name":"Direct","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":80,"wires":[]},{"id":"1a2253e8bccbf044","type":"inject","z":"909b559e8da63ab3","g":"592ffdee5f873981","name":"Data as javascript string","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"total\":467,\"used\":124,\"free\":88,\"available\":282,\"units\":\"MB\"}","payloadType":"str","x":460,"y":80,"wires":[["4b1f05c457207ae7"]]},{"id":"24b6092031129039","type":"inject","z":"909b559e8da63ab3","g":"592ffdee5f873981","name":"Same data as json","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"total\":467,\"used\":124,\"free\":88,\"available\":282,\"units\":\"MB\"}","payloadType":"json","x":450,"y":120,"wires":[["40de53dbd53a8a68"]]},{"id":"40de53dbd53a8a68","type":"json","z":"909b559e8da63ab3","g":"592ffdee5f873981","name":"","property":"payload","action":"","pretty":false,"x":630,"y":120,"wires":[["4b1f05c457207ae7"]]},{"id":"6b30c9d1264f0ab6","type":"comment","z":"909b559e8da63ab3","g":"592ffdee5f873981","name":"{\"total\":467,\"used\":124,\"free\":88,\"available\":282,\"units\":\"MB\"}","info":"","x":660,"y":160,"wires":[]},{"id":"0e47b3a6a310d146","type":"comment","z":"909b559e8da63ab3","g":"592ffdee5f873981","name":"awk -v FS=\"[:,]\" '{ printf \"%f%%\\n\", (100 * ($2 - $6) / $2) }'","info":"","x":650,"y":200,"wires":[]},{"id":"dce992b473605617","type":"comment","z":"909b559e8da63ab3","g":"592ffdee5f873981","name":"Data:","info":"","x":390,"y":160,"wires":[]},{"id":"1e226f7cee4efb99","type":"comment","z":"909b559e8da63ab3","g":"592ffdee5f873981","name":"Code:","info":"","x":390,"y":200,"wires":[]}]
Does anyone have a more elegant way to spin off processing to Bash, without using a script file or temporary data file?
Is there any way the exec node could be made more welcoming of external code interpreters such as Bash, python, perl, Csh etc?