LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-03-2006, 06:49 PM   #1
lebabyg
Member
 
Registered: Mar 2006
Location: UK
Distribution: Ubuntu Feisty
Posts: 272

Rep: Reputation: 30
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
 
Old 07-03-2006, 07:09 PM   #2
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
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.
 
Old 07-04-2006, 05:43 AM   #3
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
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.
 
Old 07-04-2006, 05:55 AM   #4
lebabyg
Member
 
Registered: Mar 2006
Location: UK
Distribution: Ubuntu Feisty
Posts: 272

Original Poster
Rep: Reputation: 30
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?
 
Old 07-04-2006, 06:15 AM   #5
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
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.
 
Old 07-04-2006, 05:40 PM   #6
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
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"
 
Old 07-04-2006, 06:12 PM   #7
lebabyg
Member
 
Registered: Mar 2006
Location: UK
Distribution: Ubuntu Feisty
Posts: 272

Original Poster
Rep: Reputation: 30
Lovely Vgui. That was easy enough. Cheers.
Graham
 
Old 07-04-2006, 06:22 PM   #8
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
*tips hat*
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
writing a bash script poiuytrewq Linux - Newbie 2 10-07-2004 11:26 PM
Writing bash script with recursion.. ray5_83 Programming 4 08-04-2004 06:44 PM
Help writing a pinging bash script dehuszar Linux - Software 3 06-18-2004 03:03 PM
Writing to a file - Bash script Skute Programming 2 03-15-2004 05:41 AM
writing bash script ankitgdit Programming 4 08-19-2003 07:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:05 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration