Run shell script from iCloud drive

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Run shell script from iCloud drive Sun Jul 21, 2019 4:30 am • by andrea_ga
I have a data gathering setup that uses Hazel to run a shell script (that creates a plot of the data) every time a text file (containing the data) is detected as changed.
The shell script calls Rscript to run a R script to do the actual plotting and saving of the data. Both the shell script and the R script are located in the same folder as the data file.
The setup is in Dropbox folders, and works perfectly. However, I am investigating the possibility of moving it to iCloud drive. After copying the folder containing both the data and the scripts on iCloud drive, and modifying the rules to point at the new folder, I have issues.
The script runs fine on Terminal, but when run from Hazel i get an error:

Code: Select all
2019-07-21 09:48:53.426 hazelworker[24042] Processing folder BCP
2019-07-21 09:48:55.689 hazelworker[24042] Battito_pressione.txt: Rule Copy of Esegui script - BCP matched.
2019-07-21 09:49:00.618 hazelworker[24042] [Error] Shell script failed: Error processing shell script /Users/andrea/Library/Mobile Documents/com~apple~CloudDocs/BCP/disegna_R.sh on file /Users/andrea/Library/Mobile Documents/com~apple~CloudDocs/BCP/Battito_pressione.txt.
2019-07-21 09:49:00.618 hazelworker[24042] Shellscript exited with non-successful status code: 2
2019-07-21 09:49:01.184 hazelworker[24042] Done processing folder BCP


The shell script is:

Code: Select all
#!/bin/sh
cd `dirname $0`
/usr/local/bin/Rscript plot.R


The R script references only the filename of the data file.

Adding the line:

Code: Select all
echo `pwd`


just before the last line, the path printed matches what Hazel is displaying in the logs:

Code: Select all
/Users/andrea/Library/Mobile Documents/com~apple~CloudDocs/BCP


Any idea what am I doing wrong?
andrea_ga
 
Posts: 6
Joined: Sun Jun 30, 2013 8:18 am

Re: Run shell script from iCloud drive Mon Jul 22, 2019 12:37 pm • by Mr_Noodle
Does the R script or interpreter require some environment variables to be set? If so, you'll probably need to set those explicitly in the script.
Mr_Noodle
Site Admin
 
Posts: 8363
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Run shell script from iCloud drive Sun Jul 28, 2019 2:11 am • by andrea_ga
Mr_Noodle wrote:Does the R script or interpreter require some environment variables to be set? If so, you'll probably need to set those explicitly in the script.


There is a
Code: Select all
.Renviron
file in my home folder that should be automatically loaded by the script interpreter, and that may be the cause.

However, while tinkering with the script, I discovered that changing it to

Code: Select all
#!/bin/sh
current_dir=`dirname $0`
cd "$current_dir"
/usr/local/bin/Rscript plot.R


makes everything work. No idea why, though.

Thank you anyway for your assistance
andrea_ga
 
Posts: 6
Joined: Sun Jun 30, 2013 8:18 am


Return to Support