LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-13-2004, 06:54 AM   #1
Andy@DP
Member
 
Registered: Aug 2003
Location: Aberdeen, UK.
Distribution: Debian, Ubuntu
Posts: 208
Blog Entries: 2

Rep: Reputation: 30
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.
 
Old 04-13-2004, 07:13 AM   #2
Andy@DP
Member
 
Registered: Aug 2003
Location: Aberdeen, UK.
Distribution: Debian, Ubuntu
Posts: 208
Blog Entries: 2

Original Poster
Rep: Reputation: 30
Oh and before I forget, can you call GUI style message popups from bash?
 
Old 04-13-2004, 07:28 AM   #3
elitecodex
Member
 
Registered: Feb 2004
Location: MD
Distribution: Fedora 9
Posts: 129

Rep: Reputation: 15
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
 
Old 04-13-2004, 07:56 AM   #4
Andy@DP
Member
 
Registered: Aug 2003
Location: Aberdeen, UK.
Distribution: Debian, Ubuntu
Posts: 208
Blog Entries: 2

Original Poster
Rep: Reputation: 30
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.
 
Old 04-13-2004, 05:06 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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.

Last edited by Hko; 04-13-2004 at 05:07 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash scripting question ajaye1971 Linux - Newbie 1 11-16-2005 07:29 PM
Bash scripting question. pete1234 Programming 23 09-22-2005 06:52 PM
bash scripting question mehesque Programming 2 03-07-2004 01:37 PM
Bash scripting question. welby Linux - Software 1 01-14-2004 10:05 AM
Bash Scripting Question RefriedBean Programming 6 09-11-2002 09:06 AM


All times are GMT -5. The time now is 06:07 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration