parallel command won't ignore config files

Viewed 66

I have a bash script that uses bash command parallel

I find that when I run the script as a non root user, parallel still checks /root/ directory for a config file named .parallel

foo.sh

#!/bin/bash

parallel --semaphore --jobs=6 "echo hello"
parallel --semaphore --wait

Running the script as root works as expected. However running as non-root gives this error

chown bob:bob foo.sh
sudo -u bob -g bob ./foo.sh
parallel: Error: Cannot change into non-executable dir /root/.parallel: Permission denied

I've tried using the --plain flag to ignore configs

parallel --semaphore --plain

I've tried using a config pointed at /dev/null

parallel --semaphore -C /dev/null

https://docs.oracle.com/cd/E86824_01/html/E54763/parallel-1.html

How can I make parallel command not check for /root/.parallel config file?

2 Answers

What is the value of $HOME in foo.sh when running?

sudo -u bob -g bob ./foo.sh

If $HOME is not changed to /home/bob but instead remains /root then that will explain what you see.

You can add:

echo $HOME

to foo.sh to check.

Or (as @jared_mamrot says) set $PARALLEL_HOME explictly.

Why does GNU Parallel need a writeable dir?

--semaphore works by creating files in the dir.

We must make sure that $HOME is a writable folder for the user that executes parallel --semaphore (or sem for short), e.g. thus:

export HOME=/tmp && parallel --semaphore <..>

Why? GNU Parallel needs $HOME to be a writeable dir, and tries to write to $HOME, which is by default a root-owned folder (/).

This is because parallel --semaphore needs to create temporary files in some location.

Related