I have some BASH scripts I want to run on my machines.
If run from the CLI/Terminal, the script works fine.
But as this is run on remote machines I wanted a bit of "feedback" on what is happening.
I added a line at the end thus:
return $?
Which SHOULD return a 0 if all is good, and other numbers if any problems happen.
But NR doesn't seem to like this idea.
This is the node: (Code follows)
[{"id":"317f1809.c0682","type":"exec","z":"e2bd5a4e.5597e8","command":"bash /home/pi/Mine/NR_Backup.sh","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Backup","x":1180,"y":610,"wires":[[],[],["3ce8bab2.acdb46"]]}]
Code:
#!/bin/bash
# ---------------------------------------
# Simple backup script v1.0
# ---------------------------------------
# Variables
myDate=`date "+%Y-%m-%d.%H.%M.%S"`
backupFolderName="$myDate"
backupSource="/home/pi/.node-red"
backupDest="/home/pi/Backups/NR"
backupFilter="*.j*"
backupExclude="lost\+found"
# Tell the user what we're working with
echo "The myDate variable contains: $myDate"
echo "A backup of $backupSource/$backupFilter will be made and stored in $backupDest/$backupFolderName"
# Begin backup
rsync -avz --progress $backupSource/$backupFilter --exclude=$backupExclude $backupDest/$backupFolderName
# We're done.
echo "Done!"
return $?
No, I didn't write the script. I'm not that smart.
Mine was a lot simpler.
Anyway.....
Running it in NR this happens:
"{"code":1,"message":"Command failed: bash /home/pi/Mine/NR_Backup.sh\n/home/pi/Mine/NR_Backup.sh: line 24: return: can only `return' from a function or sourced script\n"}"
I'm (obviously - and again) missing something.