3

I am trying to run Rscript as a different user under constrained environment with a user which do not have the access to /tmp.

As the Rscript create a tmp file, it needs access to /tmp. So i thought if i can tell Rscript to change the tmp directory and user the one i specify.

In the documention it is mentioned that Rscript looks at the $TMPDIR environment variable to set its tmp directory

Below are all the failed trails to pass the environment variable.

ATTEMPT-1: runuser -l MYUSER -c "export TMPDIR=/SOME_DIR && echo $TMPDIR"
ATTEMPT-2: runuser -l MYUSER TMPDIR=/SOME_DIR -c "echo $TMPDIR"
ATTEMPT-3: runuser -l MYUSER TMPDIR=/SOME_DIR -c "echo $TMPDIR"
ATTEMPT-3: runuser -l MYUSER -c "Rscript --TMPDIR=/SOME_DIR test.r "   --> Random stuff

All attempt failed.

I cannot move away from runuser .

Any help will be appreciated

Bhuvan
  • 4,028
  • 6
  • 42
  • 84

1 Answers1

2

I have not tried your examples but none of them could work because $TMPDIR is already replaced by the invoking shell. So, your

runuser -l MYUSER -c "export TMPDIR=/SOME_DIR && echo $TMPDIR"

becomes

runuser -l MYUSER -c "export TMPDIR=/SOME_DIR && echo "

if TMPDIR is empty or unset. Try with single quotes to avoid this:

 runuser -l MYUSER -c 'export TMPDIR=/SOME_DIR && echo $TMPDIR'

should result in the output /SOME_DIR.

danielp
  • 1,179
  • 11
  • 26