error from setting system time by the execute node on Raspberry Pi

18 views
Skip to first unread message

張漢魁

unread,
Sep 21, 2017, 2:16:47 AM9/21/17
to Node-RED
 Hello! everybody,

I would like to set system time on Rasp. Pi by execute node. as the flow in the following, I do a test, but I get some error messages on the debug window. Could anyone help me solve this problem?    Thank you in advance.

[{"id":"b1e1615.c7fd6a","type":"tab","label":"Flow 1"},{"id":"68bf0e43.9e305","type":"inject","z":"b1e1615.c7fd6a","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":113.5,"y":222,"wires":[["f5fac12c.367ff"]]},{"id":"452f23ca.607d3c","type":"debug","z":"b1e1615.c7fd6a","name":"1","active":true,"console":"false","complete":"true","x":785.5,"y":344,"wires":[]},{"id":"8dc91a58.7ad4a8","type":"exec","z":"b1e1615.c7fd6a","command":"sudo date -s=","addpay":true,"append":"","useSpawn":"","timer":"","name":"","x":499.5,"y":385.5,"wires":[["452f23ca.607d3c"],["55f3a624.42f918"],["66a8cc3f.d9c4c4"]]},{"id":"55f3a624.42f918","type":"debug","z":"b1e1615.c7fd6a","name":"2","active":true,"console":"false","complete":"true","x":779,"y":391,"wires":[]},{"id":"66a8cc3f.d9c4c4","type":"debug","z":"b1e1615.c7fd6a","name":"3","active":true,"console":"false","complete":"true","x":773,"y":441,"wires":[]},{"id":"e10e161e.f865a8","type":"debug","z":"b1e1615.c7fd6a","name":"","active":true,"console":"false","complete":"false","x":469,"y":139,"wires":[]},{"id":"f5fac12c.367ff","type":"function","z":"b1e1615.c7fd6a","name":"","func":"msg.payload = new Date().toString();\nreturn msg;","outputs":1,"noerr":0,"x":294.2421875,"y":221.796875,"wires":[["e10e161e.f865a8","8dc91a58.7ad4a8"]]}]  




/21/2017, 1:55:42 PM2msg : Object{ "payload": "/bin/sh: 1: Syntax error: \"(\" unexpected\n", "_msgid": "25c981a8.da367e" }
9/21/2017, 1:55:42 PM3msg : Object

{ "payload": { "killed": false, "code": 2, "signal": null }, "_msgid": "25c981a8.da367e" }

Dave C-J

unread,
Sep 21, 2017, 3:43:50 AM9/21/17
to node...@googlegroups.com
You can't run sudo commands using exec as that is a "escalation of privileges" that could be very unsafe.

Colin Law

unread,
Sep 21, 2017, 4:12:44 AM9/21/17
to node...@googlegroups.com
Actually you can, but only by removing the need to supply a password
for the particular commands you want to use. As Dave said it can be
dangerous so be *very* careful about which sudo commands you allow to
be invoked like this. It can be very useful however, I have a headless
pi that is connected by wifi and occasionally something goes wrong
with the wifi and the only solution seems to be to reboot, so I setup
a watchdog timer in node red so that if it loses comms for more than 5
minutes then it reboots using an exec node. To setup a command not to
need a password run
sudo visudo
and add to the end
username ALL=(ALL) NOPASSWD: /full/path/to/command

where username is the user running node-red, so may be pi, and in my
case to allow reboot the path is /sbin/reboot

Colin

On 21 September 2017 at 08:43, Dave C-J <dce...@gmail.com> wrote:
> You can't run sudo commands using exec as that is a "escalation of
> privileges" that could be very unsafe.
>
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/CACXWFw%2B80bc4aE3LzvxjTSDWw83VYUFEiEheHMz4eunZY-oy%3DQ%40mail.gmail.com.
>
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages