LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash (help writing script) (https://www.linuxquestions.org/questions/linux-general-1/bash-help-writing-script-460688/)

lebabyg 07-03-2006 05:49 PM

Bash (help writing script)
 
Hey,

This is a question for the more advanced in the community (i think!). Basically i want to write a bash script that will do this:

1.Login as root from my non-root account.
2.Then run a programme as root while still running my user account (this is so the programme will auto update, for some reason it won't as non-root user).

I can write the last bit, that's quite easy, but i can't integrate the root login. Basically i'm lazy and i just want to double-click an icon instead of opening a shell sudo-ing and then cd-ing into the correct folder!!

Any help is very much appreciated. I'm not at all prolific in writing any type of code, even when it's text based!!
Thanks in advance.
Graham

leonscape 07-03-2006 06:09 PM

Login as root and set the owner to root and the scripts suid bit.

chown root thescript.sh
chmod u+s thescript.sh

Make sure the user still has execute permissions, either by setting a group on the file and making the user a member of that group or setting execute bit for others.

spirit receiver 07-04-2006 04:43 AM

Sorry, the setuid bit won't work with shell scripts. The only possibility that I know if is to use sudo and to specify in /etc/sudoers that a user is allowed to run a program using sudo without being asked for a password.

lebabyg 07-04-2006 04:55 AM

So there isn't a way of integrating a root login into the script?? I would want the owner of the script to be a user. The user executes it, the script then logs in as root and runs a programme? Is this possible?

spirit receiver 07-04-2006 05:15 AM

You could use sudo from within that script, but you'll still have to use /etc/sudoers to make sure it won't ask for a password.

Vgui 07-04-2006 04:40 PM

Well you could do
Code:

su - root -c "some command here"
The problem of course being you still need to enter the password. As spirit receiver recommends, maybe try setting up sudo to not use a password, then just do something like
Code:

sudo "the command"

lebabyg 07-04-2006 05:12 PM

Lovely Vgui. That was easy enough. Cheers.
Graham

Vgui 07-04-2006 05:22 PM

*tips hat*


All times are GMT -5. The time now is 08:16 PM.