jhaff
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.
sudo rm /private/var/db/BootCache.
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.
ALL = NOPASSWD: rm /private/var/db/BootCache. playlist
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Consider setting the Set User Id Bit (SUID).
See this link for more information :
vhttp://meinit.nl/set-user-id-bit-demostration
See this link for more information :
vhttp://meinit.nl/set-user-id-bit-demostration
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
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
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 ?
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.
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.