node red exec node without sudo

Dear all
Hi!

node red exec node without sudo

pi@raspberrypi:~ $ bash hello.sh
HELLO
pi@raspberrypi:~ $ python hello.py
HELLO
pi@raspberrypi:~ $ sudo python hello.py
Error opening audio device (null) for capture: Connection refused

Good working : src/programs/pocketsphinx_continuous -lm hello.lm -dict hello.dic -verbose no -fwdtree no -fsgusefiller no -round_filters no -topn 1 -ds 2 -maxwpf 5 -beam 1 -lpbeam 1 -logfn /dev/null -inmic yes

Node red Exec Node : python hello.py
Error opening audio device (null) for capture: Connection refused

Could you check it!
Please help me.

How can I use shell script without sudo in Exec Node?

Welcome to the forum @shinjihun1

What is in hello.py?

Try in the exec node with the full path to the python command and the full path to the py file.

Also stop node red and start it again in a terminal and copy/paste the full output here. When pasting it use the </> button at the top of the forum entry window.

Hi Colin

hello.py:
import os
os.system("sh hello.sh")

hello.sh:
#!/bin/bash
cd pocketsphinx-5prealpha
sh hello.sh

CLI command:
src/programs/pocketsphinx_continuous -lm hello.lm -dict hello.dic -verbose no -fwdtree no -fsgusefiller no -round_filters no -topn 1 -ds 2 -maxwpf 5 -beam 1 -lpbeam 1 -logfn /dev/null -inmic yes

CLI working is good.
but in Exec Node(node-red), It does not work on that node as below.
-Error opening audio device (null) for capture: Connection refused-

on SSH CLI, the result is the same.
sudo python hello.py : Error opening audio device (null) for capture: Connection refused
sudo sh hello.sh : Error opening audio device (null) for capture: Connection refused

As a result, it is estimated that Sudo is automatically added to the Exec Node.
I am thinking about if there is a way to delete Sudo in the Exec Node.

It isn't, it will run as whatever user is running node red.

Please answer my other questions, that may give us useful information.

Also how did you install node red?

It is wrong to execute a shell script with sh hello.sh
It is wrong to execute a shell script with bash hello.sh
It is wrong to execute a shell script with os.system("sh hello.sh")

The first line of this script #!/bin/bash is supposed to indicate to Linux that the script is to be interpreted by the bash shell.
sh is not the same as bash, it is a different program with different syntax.

To execute a shell script:

  1. Include a hashbang line which specifies the interpreter program, eg #! /bin/bash
  2. Make it executable chmod +x hello.sh
  3. Invoke it by unambiguously without sh or bash but with the full pathname /home/pi/whatever/hello.sh

Those comments hold for python scripts too, indeed any interpreted language.

What do you expect will happen when the script hello.sh which you posted above calls sh hello.sh?
Is there another hello.sh in the directory pocketsphinx-5prealpha?
Is that directory included in the environment variable $PATH?
Is $PATH the same for the login shell and for the Node-Red exec node?

You can avoid these potential traps by properly and unambiguously invoking scripts.

You have not shown us the code which causes this error.

Do not use sudo unless the circumstances demand it. Any file that your program creates and leaves behind is storing up future difficulties.

For the kind reply above,thank you.
Please check above.

OS : Raspberry PI OS(32-bit) A port of debian bullseye with the raspberry Pi Desktop Release 2021-10-30
sudo apt update
sudo apt full-upgrade
pi@raspberrypi:~ $ passwd
Changing password for pi.
Current password: raspberry
New password: mrckorea
Retype new password: mrckorea
passwd: password updated successfully

Node-red install :
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) : 설치명령
sudo systemctl enable nodered.service -> 자동실행
node-red-start, node-red-stop
node-red-dashboard 설치 : npm install node-red-dashboard

Node-red Password :
node-red-stop
Password : cd .node-red, sudo nano setting.js -> PW 입력(adminAuth -- }.) ex) username(admin), PW(mrckorea)
참조 동영상 : 2021-10-07 Raspberry Pi Node-RED ID Password.mp4
sudo npm install -g node-red-admin
node-red-admin hash-pw
node-red-start

Node-red Application :
sudo apt-get install twinkle
~~
sudo nano /etc/dhcpcd.conf :
sudo raspi-config, 5. Localization Options ----, L2 Timezone, None of the above, GMT0
sudo apt install pimixer
sudo apt-get install ntpdate : NTP 설치
TTS(Text to Speech), STT(Speech to Text) :
sudo apt-get install espeak
espeak -ven-us+f5 -s170 "Press Phone Number!"
espeak -s 160 -p 95 -v ko+f3 "안녕하세요 말하는 음료수 자판기 입니다."
espeak -s 160 -p 95 -v ko+f3 "원하는 전화 번호를 입력해 주세요."
Offline speech recognition free Raspberry PI - Part 1/2 - YouTube,
Offline speech recognition free Raspberry PI - Part 2/2 - YouTube,
sudo apt-get install autoconf libtool libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev pulseaudio libpulse.dev libasound2-dev bison swig
web 다운로드 1 :
Download CMU Sphinx from SourceForge.net -o sphinxbase.tar.gz
web 다운로드 2 :
Download CMU Sphinx from SourceForge.net -o pocketsphinx.tar.gz
pocketsphinx.tar.gz sphinxbase.tar.gz
압축풀기 : tar -xzvf sphinxbase.tar.gz, tar -xzvf pocketsphinx.tar.gz
cd sphinxbase-5prealpha/, ./configure, make, sudo make install
cd ../pocketsphinx-5prealpha/, ./configure, make, sudo make install
arecord comando.wav -f cd -r 16000 -c 1 -d 3 -vv : 녹음시험
aplay comando.wav : 재생 확인
src/programs/pocketsphinx_continuous -infile comando.wav : 음성 TTS 변환
pocketsphinx_continuous -inmic yes : 실시간 마이크 음성인식
arecord comando.wav -f cd -r 16000 -c 1 -d 3 -vv
arecord attivazione.wav -f cd -r 16000 -c 1 -d 3 -vv
src/programs/pocketsphinx_continuous -lm 3891.lm -dict 3891.dic -infile attivazione.wav
src/programs/pocketsphinx_continuous -lm hello.lm -dict hello.dic -infile hello.wav : 실시간 시험 1
src/programs/pocketsphinx_continuous -lm 3891.lm -dict 3891.dic -verbose no -fwdtree no -fsgusefiller no -round_filters no -topn 1 -ds 2 -maxwpf 5 -beam 1 -lpbeam 1 -logfn /dev/null -inmic yes
src/programs/pocketsphinx_continuous -lm hello.lm -dict hello.dic -verbose no -fwdtree no -fsgusefiller no -round_filters no -topn 1 -ds 2 -maxwpf 5 -beam 1 -lpbeam 1 -logfn /dev/null -inmic yes : 실시간 시험 2
~~

Currently, there is one issue left.

pi@raspberrypi:~ $ sh hello.sh

HELLO
HELLO
HELLO
HELLO

^C
pi@raspberrypi:~ $ bash hello.sh

HELLO
HELLO
^C
pi@raspberrypi:~ $

On CLI command : OK
But in Exec Node(node-red), It does not work.
As a result, it is estimated that Sudo is automatically added to the Exec Node.
I am thinking about, there is a question about the contents related to the root/user authority setting when installing Nodered.

On Stack Overflow.com, I found Set Node-red password in root mode by Knolleary.
node.js - Set Node-red password in root mode - Stack Overflow
~~
There are not two versions of Node-RED installed on the Raspberry Pi - you are running it in two different ways.
Node-RED is installed as a system service. The service can be started and stopped using node-red-start and node-red-stop commands. By default, the service will run Node-RED as the pi user, and use /home/pi/.node-red as the user directory - where the settings.js file is located.
You can manually run Node-RED by using the node-red command. Rather than start it as a service, it will run in the terminal you ran the command in. It uses ~/.node-red as the user directory. If you run it as the Pi user, that will be /home/pi/.node-red - the same as the service instance. If you run using sudo then you are running as the root user, so the user directory will be /root/.node-red. Following from that, the settings file it will use will be /root/.node-red/settings.js - so it is that file you would need to enable adminAuth in.
You can confirm exactly what user directory and settings file it is using by viewing the log on start up where the full paths to both of these things is provided.
Note: we strongly recommend not running as root if you do not need to.
~~

You still haven't done what I asked, stop node red and start it again and post the terminal output here. When pasting it here use the </> button at the top of the forum entry window.

I did a full reinstall of the SD card once more but it doesn't work.
Node red Reinstalled : in User Mode, not admin.
Could you check attached capture .
node-red_cap.PNG
CLI_Terminal.PNG


Please let me know if there is a way to use CLI Terminal instead of Exec Node.
Thanks!

Why is it so difficult to get you to respond to requests?
For the third time, please stop node-red, start it in a terminal and copy/paste the output here. Stop and start it using
node-red-stop
node-red-start

When pasting use the </> button at the top of the forum entry window.

Also what have you now got in hello.sh?

Also please give all the debug nodes names so that it is clear which node the output is from

Also please show us how you have configured the exec node. A screenshot of that will do.

I can assure you that the exec node does not run as the user root, unless that is the user running node-red.

I notice above that you used sudo to edit settings.js. Never use sudo unless it is necessary. It will cause problems because you end up with files owned by root.

Please try and respond to all the requests.

Difficulty translating to/from Korean?

@shinjihun1 You seem to have ignored all the replies so far. Nevertheless:

Your script hello.sh, allegedly this:

#!/bin/bash
cd pocketsphinx-5prealpha
sh hello.sh

DOES NOT generate the output

HELLO
HELLO
HELLO

NOR the error

Error opening audio device (null) for capture: Connection refused

That's my last word.

Also please try the command specifying the full path to the script, so the exec node should just specify something like
/home/pi/.node-red/hello.sh
Note, not sh /home/pi/.node-red/hello.sh

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