Score:0

Run part of a script as root, but not the whole script

cn flag

I have this script with some commands in it than I want to be able to run as root, without authentication being asked, so I added this to sudoers:

all ALL = (root) NOPASSWD: /usr/bin/usblock

It allows all the users to run those commands without a problem. But there is this issue, I do not want that the regular user can do this:

sudo /usr/bin/usblock

I want all users to execute some lines, not the whole script. Is there a way to do this?

Liso avatar
sd flag
*All user to execute some lines, not the whole script*. **What if** root user `:~#` execute the script, do you want whole script to be executed ?
Jobesmor avatar
cn flag
yes, i want to "root" to able to run it.
Liso avatar
sd flag
Clarify run as whole script or some lines (for root) ?
Jobesmor avatar
cn flag
For root everything
Liso avatar
sd flag
Then the easiest way would be create two separate script, one for root user and one for regular user.
Jobesmor avatar
cn flag
I am saving that for last resource.
Liso avatar
sd flag
Can you post script sample, and what the regular user expected to run ?
Jobesmor avatar
cn flag
The regular user do mostly string handle, the only think remarkable is his he get a password from a file how belongs to root.
Jobesmor avatar
cn flag
Finally i splint the file in 2 scripts it has become overly complicated, with this solve the problem, but guess i will let the question open, in case someone know another solution.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.