script calling script as other user

Posted by viktor tron on Super User See other posts from Super User or by viktor tron
Published on 2012-06-08T10:30:16Z Indexed on 2012/06/08 10:42 UTC
Read the original article Hit count: 400

Filed under:
|
|
|

Using CentOs, I want to run a script as user 'training' as a system service. I use daemontools to monitor the process, which needs a launcher script that is run as root:

  1. :

    #!/bin/bash
    exec >> /var/log/training_service.log 2>&1
    setuidgid training training_command
    

    This last line is not good enough since for training_command, we need environment for training user to be set.

  2. :

    su - training -c 'training_command' 
    

    gives 'standard in must be tty' as su making sure tty is present to potentially accept password. I know I could make this disappear by modifying /etc/sudoers a la Bash & 'su' script giving an error "standard in must be a tty" but i am reluctant and unsure of consequences.

  3. :

    runuser - training -c 'training_command' 
    

    gives runuser: cannot set groups: Connection refused. I found no sense or resolution to this message.

I am stuck. Is this something so hard to achieve?

I appreciate all insight and guidance to best practice.

© Super User or respective owner

Related posts about linux

Related posts about shell