4

I want a script X.sh to switch users and perform an action, but so far I have this:

 #!/bin/sh

 sudo su partner -s /bin/bash 
 supervisord -c ~/supervisord.conf
exit

I want that the user partner execute supervisord and exit, but all I get is a switched user in the comand line a bash shell, doing the su partner -s /bin/bash is the only way in which I can access the partner user.

Please Help

ocespedes
  • 165
  • 6
  • sudo su partner -c supervisord? – Rmano Apr 16 '14 at 22:39
  • Sorry I forgot my .conf file, I tried that way and it did not work, I'll edit my question – ocespedes Apr 16 '14 at 22:51
  • @Rmano Had the right idea. sudo su partner -s /bin/bash -c 'supervisord -c ~/supervisord.conf' That is assuming ~/supervisord.conf is in fact in the partner user's home directory. – ptierno Apr 16 '14 at 22:53

1 Answers1

5

You should use sudo -u partner supervisord -C ~/supervisord.conf instead, and set up your current user in the /etc/sudoers file. An entry to allow user "current" to execute this command as "partner" would look something like this:

current ALL=(partner:partner) NOPASSWD: /path/to/supervisord

Make sure and use visudo instead of trying to edit the sudoers file manually. There is a more in-depth but simple explanation of the sudoers file syntax here.

jkt123
  • 3,530
  • 22
  • 24