I am trying to run an Rscript inside an EC2 by supplying a set of scripts to the instance from S3. The EC2 instance is a custom AMI running R and R Server. When the instance is fired up, it fetches it's scripts from S3, and runs them, then closes down.
The problem in it's simplest form is that when I call Rscript
inside the bash scripts, it does not do anything! Drastically cut down example:
var userData= `#!/bin/bash
# create tree & get scripts
mkdir ./monkey
cd ./monkey
mkdir ./scripts
aws s3 cp s3://xxxxxxx/scripts/ ./scripts/ --recursive
Rscript > log_test`;
The scripts appear all as expected from S3. Everything works. Except, the log file does not exist, because Rscript does nothing.
However, if I log into the instance and rerun the script or type by hand, it works fine. And of course I can run Rscript render etc. no problem at all.
Help. Why is this happening?
Update 1: following @Marcin 's comment
R scripting front-end version 4.0.3 (2020-10-10)
Error in with_pandoc_safe_environment(system(paste(shQuote(path), "--version"), :
The 'HOME' environment variable must be set before running Pandoc.
Calls: <Anonymous> ... FUN -> get_pandoc_version -> with_pandoc_safe_environment
Execution halted
So, the Rscript returned the version. No clue why it didn't appear in the log file though. Red herring. The actual problem is something to do with pandoc wanting the HOME environment variable set. I guess that explains why it only works when I'm logged in over ssh? Hmmm. What's the best way to fix this?
I've tried to just stick HOME="/root"
in the script. But it makes no difference.
Update 2
By actually setting the env variable correctly:
export HOME="/root"
it's now working. Wo hooo... Credit goes to Marcin.