Question

I'm trying to use GNU Parallel in order to run a script with several parameters on a remote machines. This looks somewhat like:

parallel --onall -S remote-machine  /shared/location/script.sh ::: param_a param_b

/shared/location/script.sh is using git. So I get this error:

git: command not found

If I log in to remote-machine manually and run /shared/location/script.sh with param_a or param_b everything works fine. So I checked the $PATH variable and found out that if I run something on remote-machine using GNU parallel, it looks like PATH=/usr/bin:/bin:/usr/sbin:/sbin. If I run it directly from the machine it has also /local/bin/git.

Why is it that way and how to overcome?

Thanks in advance

Was it helpful?

Solution

GNU Parallel uses ssh for remote execution, so the $PATH is the same as you would see when you run a non-interactive ssh session:

ssh server echo '$PATH'
parallel -S server --onall {} '$PATH' ::: echo

The reason you see a different $PATH when you log in is that interactive sessions may set another $PATH.

You can force parallel to copy an environment variable using --env:

parallel --env PATH -S server --onall {} '$PATH' ::: echo
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top