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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


0
jgiordanoCommented:
add the above to your sudo file
0
97WideGlideCommented:
Consider setting the Set User Id Bit (SUID).

See this link for more information :
vhttp://meinit.nl/set-user-id-bit-demostration
0
The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

omarfaridCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.