How to run a bash script from node red?

Sorry folks, I’ve tried searching and the results were somewhat unhelpful.

I am wanting to invoke a shell script (bash script?) from Node-red.

I tried the exec node, but no luck.

Found “BIGEXE” and that didn’t work either.

I don’t need any extra stuff. The whole name is sent to the node upon invocation.

1 Like

The exec node is exactly what you want.

What didn’t work about it? Any error messages etc? How did you have it configured?

(Blush)

This is embarrassing for me.

I don’t know why it is, but sometimes I have to ask a “dumb” question before I can resolve it myself.

What I missed is in the EXEC node I was only entering the file name of the script I wanted to run.
I now realise I have to enter:
bash (filename)
and it works.

I am sorry.

Believe me, I don’t like to waste people’s time.

1 Like

Just on this, kinda…

I see there is a place where people can upload their own flows.

I have a couple which only use the standard nodes and may be handy for people.

Is it ok if I do so?

Alas there is a slight caviet (spelling?) that it uses an external bash script in what it does to achieve everything.

I don’t want to upload stuff which won’t work “as is” but if it needs external (or foreign) stuff, I don’t know how to include it as a part of the package.

no problem - you could also possibly set your script to be executable eg chmod +x yourscript.sh and then you may not need to call bash… but yes lots of ways to do his.

Yeah, thanks.

It was more that I was completely missing the BASH part.

So in the “execute” filed I was only putting the file name.

Suddenly it hit me that I need to put bash then the file name.

All working now.

If the file has been made executable and the first line of the file is
#!/bin/bash
then you should just be able to put the full path to the script in the exec node.

I use bash scripts to backup Node Red and Motion files from Pi systems in my network. I run this with Node Red running on Ubuntu. I had file permission issues until I placed the bash script into my .node-red directory.
Now, using Node Red, I can automate the backup of all the Pi systems in my network.
The exec node just needs the file path: /home/will/.node-red/backup-204.sh with 'append' unchecked.
I set the file to executable.
Sample bash code:

#!/bin/bash
#back up Node Red and motion files from remote Pi to Dropbox
#I run this with Node Red running on Ubuntu 18.04
#I place this bash file in my .node-red directory


#sprinkler-204 is my sprinkler system pi at 192.168.1.204
#it runs Node Red and also a motion cam inside my garage

#espeak needs to be installed for audible speach
#delete the espeak lines if you don't want to hear them
espeak "204 file backup in progress"

today=`date +%Y-%m-%d.%H:%M:%S`

espeak "creating updated directories"
#make new directories named with time stamp
mkdir /home/will/Dropbox/net/sprinkler-204/motion/old/$today
mkdir /home/will/Dropbox/net/sprinkler-204/node-red/old/$today

espeak "moving old files"
#move previous backup files to new directories
mv /home/will/Dropbox/net/sprinkler-204/motion/*.* /home/will/Dropbox/net/sprinkler-204/motion/old/$today
mv /home/will/Dropbox/net/sprinkler-204/node-red/*.* /home/will/Dropbox/net/sprinkler-204/node-red/old/$today

espeak "getting files from pi"
#backup current files from the pi
#ssh keys need to be set up for this to work without a password
scp pi@192.168.1.204:/etc/motion/* /home/will/Dropbox/net/sprinkler-204/motion
scp pi@192.168.1.204:/home/pi/.node-red/*.* /home/will/Dropbox/net/sprinkler-204/node-red
1 Like

Hopefully an easy question here but here we go:
I have an exec node running executing a bash command to create a fullscreen chromium browser page. It worked beautifully for about 10 reboots during testing (which also involved simply cutting power and rebooting). The debug message has not changed during this time. Is there some process I'm missing that needs to be dealt with (i.e. escaping the script on shutdown or other)?

(The Pi is remote from me at the moment so will update with debug messages from the second two outputs in the morning.)

I don't think this question is relevant to the original thread, which is two years old. Please ask the question again in a new thread.
Note however that, assuming that your pi boots off an SD card then every time it is powered down without a proper shutdown sequence then there is a small chance that the SD card will be corrupted. So if you have something that is working, and continues to work after a proper shutdown and reboot, but without any changes stops working after a forced power down then you have to suspect the card. So I suggest that you re-image the card and restore your flows and see if it then works.

Sorry I didn't qualify this as a/the solution.

So just to help anyone else (now) reading this thread.