0

I have a .sh script which contains a set of functions. I have made the script executable (chmod 777).

If I want to run a function as my current user I simply do:

. /path/to/script/functions.sh && fc_number1 "${item1}" "${item2}" &

This works fine. However I have another function, that needs to be run by a different user with different privileges.

I have tried:

sudo -unewuser . /path/to/script/functions.sh && fc_number2 "${item1}" "${item2}" "${item3}"
sudo -unewuser -c "bash -c fc_number2 ${item1} ${item2} ${item3}"

Neither of which works. I simply get sudo: .: command not found or bash: export: fc_number2: not a function, or some other error.

Is there something else I need to do to make this work. Everything I read basically comes back to one of the two options I have tried above.

IGGt
  • 2,137
  • 8
  • 28
  • 43
  • You could use a wrapper script that contains `. /path/to/script/functions.sh && fc_number2 "${item1}" "${item2}" "${item3}"` and run it as `sudo -unewuser wrapper_script.sh`. If necessary you could also create a wrapper script that takes command line arguments and passes them to the function call. – Bodo Feb 18 '19 at 13:41
  • It is better to not give scripts a `.sh` ending. And if you give a mode of `777` then you give everyone on the system, permission to write/change the script. – ctrl-alt-delor Feb 18 '19 at 13:53
  • the 777 was purely to try and get it working on my test environment. It just means there is one less thing that may be preventing it working. Once I have it working it would then refine it back down to the bare minimum privileges needed to make it work. – IGGt Feb 18 '19 at 13:58

0 Answers0