 |
Linux Format forums Help, discussion, magazine feedback and more
|
| View previous topic :: View next topic |
| Author |
Message |
MGE

Joined: Thu Sep 08, 2005 3:53 am Posts: 94 Location: Manchester
|
Posted: Wed Jan 25, 2006 2:33 am Post subject: Bash Scripting Help |
|
|
Howdy
I have been trying to create a script to automate various processes, however, I can't figure out how to run certain parts of the script as root, and certain parts as my normal user.
I don't want to run the entire script as root, just the odd section.
I tried just using the su command, and then realised that I was now a totally different user and no longer executing my script.
Arse.
I realise su isn't the best idea, however for testing purposes, its fine.
Is there a way to do this?
Am I nuts for even thinking about using su in a script?
My second idea was to start another shell as root, however I'm not entirely sure
how to do that from a script.
Cheers in advance. _________________ Pentium 4 3.2Ghz Prescott 1MB Cache
Abit IC7 (875P Chipset)
3GB Corsair Dual Channel DDR
Nvidia GeForce 6600GT
500GB (SATA2-ReiserFS) Main drive
500GB (PATA-ReiserFS) Media drive
120GB (PATA-NTFS) Legacy data
OS: SimplyMEPIS 8 |
|
| Back to top |
|
 |
MartyBartfast LXF regular

Joined: Mon Aug 22, 2005 8:25 am Posts: 780 Location: Hants, UK
|
Posted: Wed Jan 25, 2006 9:09 am Post subject: RE: Bash Scripting Help |
|
|
Sounds like you want to use sudo, e.g
sudo kill 1234
will kill off a process using root privs.
You need to add an entry to /etc/sudoers which defines which users can execute sudo, and which commands they can execute. e.g. you could specify in sudoers that user fred can only execute cp (e.g. if you want to copy protected files) but can't run any other commands.
man sudo
should give you all the info you need. _________________ I have been touched by his noodly appendage. |
|
| Back to top |
|
 |
nelz Moderator

Joined: Mon Apr 04, 2005 12:52 pm Posts: 7997 Location: Warrington, UK
|
Posted: Wed Jan 25, 2006 9:39 am Post subject: RE: Bash Scripting Help |
|
|
Yep, sudo is the way to go. You'll need to specify the full path to the commands that you want the user to be able to run, and tell sudo not to ask for a password for these commands. Otherwise it will stop the script to prompt for your password (not the root password). Here's a part of my /etc/sudoers file.
| Code: | | nelz ALL = NOPASSWD: /bin/mount,/bin/umount |
Note the comment at the top of /etc/sudoers, this file must be edited with the visudo command, not loaded directly into an editor. Run visudo as root and it will load the file into whatever program you have defined in $EDITOR. You can change this at the time you run visudo with, for example
_________________ Unix is user-friendly. It's just very selective about who it's friends are. |
|
| Back to top |
|
 |
MGE

Joined: Thu Sep 08, 2005 3:53 am Posts: 94 Location: Manchester
|
Posted: Wed Jan 25, 2006 11:39 am Post subject: RE: Bash Scripting Help |
|
|
Thanks everyone, I had been trying sudo but hadn't set up the sudoers file correctly.
I'll give that a go.
Thanks again  _________________ Pentium 4 3.2Ghz Prescott 1MB Cache
Abit IC7 (875P Chipset)
3GB Corsair Dual Channel DDR
Nvidia GeForce 6600GT
500GB (SATA2-ReiserFS) Main drive
500GB (PATA-ReiserFS) Media drive
120GB (PATA-NTFS) Legacy data
OS: SimplyMEPIS 8 |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|