set shell user to call script in Rails

Asked

Viewed 44 times

0

I need to call a shell script from Rails, with a specific shell user.

Example:

update_response = `#{deploy_dir}/./update.sh`

By default my system is using root user.

I would like to know, given this example, if you have how to specify the user and if you have a means to generalize script calls to the same user.

2 answers

0

You can use sudo -u username

0

Solution found using the shell itself to call the script with another user.

update_response = `su -c '#{deploy_dir}/./update.sh' - #{user}`

We can from this solution create a generic function for script calls by passing script path and a user per parameter.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.