How to run a bash script from node red?

#1

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.

0 Likes

Exec node cannot find any of my commands
#2

The exec node is exactly what you want.

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

0 Likes

#3

(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.

0 Likes

#4

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.

0 Likes

#5

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.

0 Likes

#6

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.

0 Likes

#7

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.

0 Likes

#8

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
3 Likes