My script use an access to mysql to get command arguments to launch Rscript. Its use is as follows : Rscript $RFILE $ARGUMENTS (RFILE corresponding to path to Rscript, and ARGUMENTS corresponding to path file used and agr).
I try, different way, but I still have errors, here a copy of my bash script :
#!/usr/bin/env bash
# Execute R process
# -----------------
### Mysql Setup ###
USER=...
PASS=...
HOST=...
DB=...
# Get Job ID process
# Use to retrieve args in my DB
ID=$1
# Get script name
RFILE=$(mysql -u$USER -p$PASS -e "SELECT script_name FROM JobProcess WHERE script_run_id=$ID;" $DB)
SUBSTRING="script_name"
RFILE="${RFILE//$SUBSTRING}"
# Get script_args
ARGUMENTS=$(mysql -u$USER -p$PASS -e "SELECT script_args FROM JobProcess WHERE script_run_id=$ID;" $DB)
SUBSTRING2="script_args"
ARGUMENTS="${ARGUMENTS//$SUBSTRING2}"
RUN="Rscript $RFILE $ARGUMENTS"
# Try Different execute process
Rscript $RFILE $ARGUMENTS
#eval "$RUN"
#`Rscript $RFILE $ARGUMENTS`
#$RUN
I verified my command line (via echo), and if I made a copy-paste to my shell I can run my R script. But from my bash, I can't execute my script (but command line is good).
By using : Rscript $RFILE $ARGUMENTS, Rscript $RFILE $ARGUMENTS
and $RUN, I have this error :
Error in parse(text = args[[i]]) :
unexpected end of input in ""path_in='/Users/GR/web-app/Rproject/Inputs/Rscript/Gene-level"
Calls: eval -> parse
Execution halted
By using : eval "$RUN", I have this error :
/Users/GR/web-app/Rproject/Scripts/Rscript.sh: line 38: /Users/GR/web-app/Rproject/Scripts/arg_file_test.R: Permission denied
/Users/GR/web-app/Rproject/Scripts/Rscript.sh: line 44: path_in<-"/Users/GR/web-app/Rproject/Inputs/Rscript/Gene-level Description for Modules.csv": No such file or directory
If I try this in my shell script, all works fine :
SCRIPT="/Users/GR/web-app/Rproject/Scripts/arg_file_test.R"
FILE1="path_in='/Users/GR/web-app/Rproject/Inputs/Rscript/Gene-level Description for Modules.csv'"
FILE2="path_in2='/Users/GR/web-app/Rproject/Inputs/Rscript/Template_Auto.csv'"
FILES="\"$FILE1\" \"$FILE2\""
ARG="l=32 w=33"
RUN="Rscript $SCRIPT $FILES $ARG"
Someone has an idea ?
Thanks