Link to home
Start Free TrialLog in
Avatar of jhaff
jhaffFlag for Afghanistan

asked on

need to use sudo in script

I need a simple script that will delete the boot cache file at /private/var/db/BootCache.playlist.

sudo rm /private/var/db/BootCache.playlist works in terminal, but i need to put in the root password.  how can i accomplish in a script without leaving the root password in plain text?

my goal is to put this into a logout hook so the computer doesn't freeze on reboot... i need this script to run as any user.

any help would be great.
Avatar of jgiordano
jgiordano
Flag of United States of America image

ALL = NOPASSWD: rm /private/var/db/BootCache.playlist


SOLUTION
Avatar of jgiordano
jgiordano
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 97WideGlide
97WideGlide

Consider setting the Set User Id Bit (SUID).

See this link for more information :
vhttp://meinit.nl/set-user-id-bit-demostration
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You've already been given a solution, but I just wanted to clear up a misconception.

When you run sudo, it isn't prompting for the root password, it's prompting you for the password of the user you are running sudo from.
Avatar of jhaff

ASKER

i've tried to add the above line(s) with no success.  i keep getting a syntax error: parse error...

am i doing something wrong?  is there a specific place this line needs to go?  do i need to recompile the file somehow?? help i'm at a loss... thanks much
Did you try my comment?  It's easy, probably the best AND SAFEST way to do things in your situation and there's no need to learn the /etc/sudoers syntax.

When a setuid bit is set to an executable, the script will be executed as if it was executed by the owner of the file - simple.  One chmod command and you're good to go.

Anyone have any cons to solving the OP's question this way ?
Well, unless OS/X is the exception to just about all other Unix/Linux flavours, then setuid bits on scripts are ignored.
Tintin,

Yep, nice point.  Depends on the version, I guess.

http://osvdb.org/15639

I'm done.
There was no follow up provided by the jhaff.  We can only help if we get some feedback as to whether our solutions or requests for more information are provided.
Split points evenly:

Answer : http:#22990998 
Assist    : http:#22990909