?
Solved

need to use sudo in script

Posted on 2008-11-18
14
Medium Priority
?
780 Views
Last Modified: 2013-12-21
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.
0
Comment
Question by:jhaff
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 11

Expert Comment

by:jgiordano
ID: 22990906
ALL = NOPASSWD: rm /private/var/db/BootCache.playlist


0
 
LVL 11

Assisted Solution

by:jgiordano
jgiordano earned 248 total points
ID: 22990909
add the above to your sudo file
0
 
LVL 8

Expert Comment

by:97WideGlide
ID: 22990982
Consider setting the Set User Id Bit (SUID).

See this link for more information :
vhttp://meinit.nl/set-user-id-bit-demostration
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 40

Accepted Solution

by:
omarfarid earned 252 total points
ID: 22990998
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
 
LVL 48

Expert Comment

by:Tintin
ID: 22991229
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
 

Author Comment

by:jhaff
ID: 23006638
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
 
LVL 8

Expert Comment

by:97WideGlide
ID: 23007438
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
 
LVL 48

Expert Comment

by:Tintin
ID: 23009049
Well, unless OS/X is the exception to just about all other Unix/Linux flavours, then setuid bits on scripts are ignored.
0
 
LVL 8

Expert Comment

by:97WideGlide
ID: 23009292
Tintin,

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

http://osvdb.org/15639

I'm done.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 23765193
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
 
LVL 8

Expert Comment

by:97WideGlide
ID: 23798862
Split points evenly:

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
This is a tech scam I recently helped my parents through.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question