Quantcast
Channel: Allowing {USER} to run a command against a process owned by another user - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2

Answer by Doopz for Allowing {USER} to run a command against a process owned by another user

$
0
0

I found the solution to my troubles with the assistance of @steeldriver.

To answer this in chronological order:

How to run a command as {USER} on a process owned by a different 'user / account / role'?

In order to run a process on an {ALTERNATIVE_USER} while acting as {USER}, we must make use of sudo, to which you can then specify which exact user should be running the command, like so:

sudo -u {ALTERNATIVE_USER} {COMMAND}

How can I trigger a {COMMAND} to run in the background allowing the current script to continue?

The script appears to freeze as the process is triggered, it is not frozen it is simply waiting for the newly triggered command to end, which it won't as it is acting on the initially triggered process, which will never reach its end.

To do this when we initiate the command that hangs, we must specify an outlet for it so it has somewhere to hang. This can be done by pointing to an alternative location, in my instance I used > /dev/null.

Lastly, what I needed to do was run it in the background, which can be done by appending an &.

Final point, specifically for me I did not wish to receive a response, I simply wanted the command to run off and do as I said, so I swapped out exec() in favour of shell_exec().

shell_exec(sudo -u {USER} cpulimit --pid {ID} --limit 60 /dev/null &");

Viewing all articles
Browse latest Browse all 2

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>