1

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.

monkey
  • 1,213
  • 2
  • 13
  • 35
  • 1
    ssh to the instance and inspect `/var/log/cloud-init-output.log`. – Marcin Nov 25 '20 at 00:21
  • It doesn't look like you're actually passing a script to Rscript – Dason Nov 25 '20 at 01:56
  • @Dason All of that detail is excluded for clarity. It wasn't relevant to the question! Cheers. – monkey Nov 25 '20 at 03:07
  • @Dason Oh, actually, `aws s3 cp s3://xxxxxxx/scripts/ ./scripts/ --recursive` copies an entire folder full of scripts from the cloud. But as I said I edited the info down for clarity so the question wasn't too crowded. Cheers, – monkey Nov 25 '20 at 03:13
  • you may also be interested in https://github.com/pandoc/dockerfiles – mb21 Nov 25 '20 at 10:13

0 Answers0