LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Getting bash script files to run as root user (https://www.linuxquestions.org/questions/programming-9/getting-bash-script-files-to-run-as-root-user-545072/)

helptonewbie 04-11-2007 05:39 AM

Getting bash script files to run as root user
 
Hello to all,
What i am trying to do is get my bash scripts to run when executed as any user. Basically all scripts are locked down to only allow root to execute them. i have used things like the kde desktop shortcut which links to the script file and i can set the kde link to run it as root and it asks me for the root password thats fine. But inside that file will be another command at some point trying to execute the next bash script i want run. This is where the problem is, it doesn't run that command and thats what i need to happen. I've even tried it using the "kdesu" command which is basically the same thing as the desktop link shortcut method. Which does the same problem. Also if the script is run and i set the "kdesu" inside the file that was run to see if it even prompts me for a password to then run the next script it doesn't do that.

So why does my script run yet not execute the next bash script i want it to.
And
How can i get it to do this.

Thanks for any help
Mark

PS- i've even tried sudoers but even after putting the username into the sudoers file it still didn't work and said username isn't in sudoers file.

omnio 04-11-2007 06:16 AM

If I understood right, you have a chain of scripts. Inside a script, how do you call the next script, sourcing it or executing it? If you just execute it, what about sourcing? For example:

Executing:
Code:

#!/bin/bash
# script1

.....
./script2
.....

Sourcing:
Code:

#!/bin/bash
# script1

.....
source script2
.....


helptonewbie 04-11-2007 06:39 AM

thanks for the reply, it needs to execute the next script, it would be better any way. As one script executes the next script then the next script executes another script and so on. i can get the first script i execute to run fine as root, but it doesn't execute the command from within that same script which would run the next script that i also want run as root.

i tried the source thing to and that didn't work, again it ran fine when i execute the command from just the normal bash after su'ing to root. But when the same command is run from within the executed script its like it just scripts that command but it still runs the rest??? :confused:

Cheers for your reply

cfaj 04-12-2007 11:49 AM

Quote:

Originally Posted by helptonewbie
Hello to all,
What i am trying to do is get my bash scripts to run when executed as any user.
...
So why does my script run yet not execute the next bash script i want it to.
And
How can i get it to do this.
...

PS- i've even tried sudoers but even after putting the username into the sudoers file it still didn't work and said username isn't in sudoers file.


If "said username isn't in sudoers file", you didn't put it there. Did you use visudo to edit the sudoers file? What did you put in the file?


bigearsbilly 04-13-2007 04:06 AM

what are you trying to achieve exactly?

there's maybe a better way to do it.

helptonewbie 04-13-2007 09:09 PM

Quote:

Originally Posted by cfaj

If "said username isn't in sudoers file", you didn't put it there. Did you use visudo to edit the sudoers file? What did you put in the file?


Er nope just edited the main sudoers file, put my username in it and all all, exactly how it was for root :) wrong i take it :P

--------------
Quote:

what are you trying to achieve exactly?

there's maybe a better way to do it.

I've written a program basically and i've written it basically with root accessing all the commands and so on inside it. Of course not wanting to run the program when i run it and logging in as root or 'su' to root, i want to do it by clicking icon, and the thing runs as any user as root as long as they know the root password. OBVIOUSLY only the right people have the root password :rolleyes:

Thanks for the replies peeps :)


All times are GMT -5. The time now is 12:13 PM.