LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash scripting question (https://www.linuxquestions.org/questions/programming-9/bash-scripting-question-169503/)

Andy@DP 04-13-2004 06:54 AM

bash scripting question
 
Hello,
I have a script that I wrote to check if the modem is connected or not. If connected it disconnects and vice versa. I wrote the script because my modem is a USB ADSL and I wanted an easy way to (dis)connect. I have to run the script as root, and don't want to chmod the app it calls.

1. How can I change to root in the script?
(I tried su at the top but that quits the script once the password is typed)

2. Is it possible to get KDE to display 2 icons for the script like the trash icon, 2 state?

Thanks in advance,
Andy.

Andy@DP 04-13-2004 07:13 AM

Oh and before I forget, can you call GUI style message popups from bash?

elitecodex 04-13-2004 07:28 AM

Have you tried
Code:

su -c 'scriptname.sh'
When you said that you tried su at the top, Im not sure what you meant by that. Thats why Im suggesting this.

Keep in mind, Im still a newbie :)

Andy@DP 04-13-2004 07:56 AM

I mean that the script does some stuff then

su # inside the script

then is supposed to carry on with more. Sorry if it was not clear the first time.

Hko 04-13-2004 05:06 PM

Well. It's probably best to have 2 scripts: the second one for the root part, which you call from the first script with:
Code:

sudo /path/to/second/script
For this to work root has agree with this by putting this in /etc/sudoers (using "visudo" as the editor):
Code:

<user> <hostname> = NOPASSWD:  /path/to/second/script
Note:

(1) Replace "<user>" with the name of the user you want to allow to run the script as root without entering the root password

(2) Replace "<host>" with the hostname of the computer. "localhost" will not do (on my system at least), use the output of "hostname".

Hope this helps. See "man sudo" and "man sudoers" for more information.


All times are GMT -5. The time now is 01:09 PM.