1

I have a shell script that adds users from a csv to a running nextcloud instance. The nextcloud instance is running inside docker containers. For some reason, I am getting an error from the line that is using process substitution <(anonymous pipe). Other than the errors that I'm getting back, the script does everything I expect it to. Even with the errors, the users are added and I can see no adverse side effects. Any ideas? Here's my script.

#!/bin/bash
input_file="./users.csv"

#   Input File
#   jack,Jack Ripper,test_group,
#   jill,Jill Ripper,test_group,
#   johny,Johny Appleseed,test_group,

while IFS=, read -r f1 f2 f3
do

<(docker-compose exec -T --env OC_PASS=nomoremonkeysjumpingonthebed --user www-data app php occ \
    user:add --password-from-env --display-name="${f2}" --group="${f3}" "$f1" )

done <"$input_file"

exit 0

When I run that script I get the following on stdout.

./batch_users.sh: line 11: /dev/fd/63: Permission denied
./batch_users.sh: line 11: /dev/fd/63: Permission denied
./batch_users.sh: line 11: /dev/fd/63: Permission denied
quarterpi
  • 113
  • 1
  • 4
  • 1
    Are you sure that you have pasted your script correctly? Line 11 is blank. – Michael Hampton Mar 22 '19 at 02:08
  • Yes, that is an exact replica of my batch_users.sh file. – quarterpi Mar 22 '19 at 02:13
  • @MichaelHampton I also tried removing the empty lines inside of the do block. Then it returns an error on the line `done <"$input_file"`. Trick is, if I put anything other than the anonymous pipe inside of the do block there is no error – quarterpi Mar 22 '19 at 02:20

2 Answers2

2

It's very simple. Your script is actually attempting to EXECUTE the named pipe. <() process substitution is used to subsititute files, usually used as arguments to commands. As a standalone file on a line, this becomes a command by itself and you get a "permission denied" error because named pipes are not executable.

I don't really know what you are trying to accomplish here , so you I can't offer you a correction, but what you're doing is definitely not right.

  • Sorry for taking so long to accept your answer. The reason I used the named pipe is the while loop was exiting after the first run through the do block. Spawning a new process for each allows all the users to be added. I know it's hacky and there's probably a better way but it does work. I added `echo <()` to silence the error. Now it just returns `/dev/fd/63` for each entry in the csv. – quarterpi Mar 25 '19 at 19:17
0

In case someone stumbles upon this in the future and is tempted to use my original script, here is a better way.

#!/bin/bash

input_file="./users.csv"

#   Input File
#   Jack Ripper,jack,test_group
#   Jill Ripper,jill,test_group
#   Johny Appleseed,johny,test_group

while IFS=, read -r f1 f2 f3
do
sh -c "docker-compose exec -T --env OC_PASS=nomoremonkeysjumpingonthebed --user www-data app php occ \
    user:add --password-from-env --display-name=\"${f1}\" --group=\"${f3}\" \"$f2\" " < /dev/null
done <"$input_file"
exit 0

No longer using process substitution which in this case is a much better option.

quarterpi
  • 113
  • 1
  • 4