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.
jhaffAsked:
Who is Participating?
 
omarfaridConnect With a Mentor Commented:
please add to /etc/sudoers

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

Please see:

http://www.gratisoft.us/sudo/man/sudoers.html#nopasswd_and_passwd
0
 
jgiordanoCommented:
ALL = NOPASSWD: rm /private/var/db/BootCache.playlist


0
 
jgiordanoConnect With a Mentor Commented:
add the above to your sudo file
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
97WideGlideCommented:
Consider setting the Set User Id Bit (SUID).

See this link for more information :
vhttp://meinit.nl/set-user-id-bit-demostration
0
 
TintinCommented:
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.
0
 
jhaffAuthor Commented:
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
0
 
97WideGlideCommented:
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 ?
0
 
TintinCommented:
Well, unless OS/X is the exception to just about all other Unix/Linux flavours, then setuid bits on scripts are ignored.
0
 
97WideGlideCommented:
Tintin,

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

http://osvdb.org/15639

I'm done.
0
 
TintinCommented:
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.
0
 
97WideGlideCommented:
Split points evenly:

Answer : http:#22990998 
Assist    : http:#22990909
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.