LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   scripts with root priviliges (https://www.linuxquestions.org/questions/linux-software-2/scripts-with-root-priviliges-472265/)

sycamorex 08-09-2006 06:44 AM

scripts with root priviliges
 
Hi,
I wrote a short script mounting/unmounting external sata drives or pen drives. I installed slackware on a new box, and the problem is that when I run the script as a normal user, I get
the error about not having permissions to mount it (fair enough),
but when I su and run the script as root the script can't be found. obviously it's not in the path, but I do not want to add
normal_user/home/bin to root's path. I am sure some time ago I managed to do it without adding anything to the root's path.
Obviously, I can always cd /home/bin/ and run the script, but that's not the point.

thank you

druuna 08-09-2006 07:04 AM

Hi,

Why not use su - on the mount command only and run the script as regular user?

I.e:

#!/bin/bash

some code...
more code...

su - -c "mount -o loop -t iso9660 /data/Multimedia/"

more code....


Su's -c switch lets you enter a command (man su for details).

You will be asked for a password.

By the way: If you use su instead of su -, root's environment is not parsed.

PS: You could also install/configure sudo.

Hope this helps.

rahulk 08-09-2006 07:07 AM

Quote:

Originally Posted by sycamorex
Hi,
I wrote a short script mounting/unmounting external sata drives or pen drives. I installed slackware on a new box, and the problem is that when I run the script as a normal user, I get
the error about not having permissions to mount it (fair enough),
but when I su and run the script as root the script can't be found. obviously it's not in the path, but I do not want to add
normal_user/home/bin to root's path. I am sure some time ago I managed to do it without adding anything to the root's path.
Obviously, I can always cd /home/bin/ and run the script, but that's not the point.

thank you

do the following:-

[root@yourcomputer /] whereis ls

then whatever the path is suggested by the command, put your script in there and then it will work like a normal linux command. Also remember, the permission should be 777 on the file, but mounting wont be allowed to any other user except root.

Rgds,
Rahul.

sycamorex 08-09-2006 07:52 AM

Thanks guys, I will try both methods at home.
I know sudo is installed on my box, how do I configure it?

thanks

druuna 08-09-2006 08:49 AM

Hi,

I don't use sudo myself, but here are a few links:

sudo setup guide
man sudoers
man sudo

and last, but not least:

sudo main page

Hope this helps.

sycamorex 08-09-2006 09:16 AM

thanks, I will play with it


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