Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gogreen1

macrumors 6502
Original poster
Nov 20, 2017
262
14
I want to create an executable file for my desktop with a command to clear the DNS cache. I can create the executable file just fine, but a sudo command, of course, requires an administrative password. Is there a different command I can use to clear the DNS cache that doesn't require a password? Thanks.
 
The setuid bit is the usual way to do this, but it won't work on a shell script if that's what you have.

Thanks, MC6800, but this is far beyond my capability. I think I'm going to just live with clearing the cache occasionally manually.
 
But the sudo command requires a password, right? That's what I'm trying to avoid.
 
sudo vi /etc/sudoers

change the line:

%admin ALL = (ALL) ALL

to

%admin ALL = (ALL) ALL NOPASSWD: ALL

start a new shell.

Horrible security but it's obvious you don't care.
 
  • Like
Reactions: rmpbklyn
Just download the free "OnyX" app and run it in auto mode. One of its functions is to clear caches. It's a safe app and is currently updated to support High Sierra. Make sure you download the version that's for the version of macOS you're using.
 
  • Like
Reactions: gogreen1
sudo vi /etc/sudoers

change the line:

%admin ALL = (ALL) ALL

to

%admin ALL = (ALL) ALL NOPASSWD: ALL

start a new shell.

Horrible security but it's obvious you don't care.

It goes without saying that this would be very bad.

You can also just specify a command directly, e.g.
Code:
%admin    ALL = NOPASSWD: /usr/bin/killall -HUP mDNSResponder

Then any admin can just use:
Code:
sudo killall -HUP mDNSResponder

Without having to enter a password, but only for this specific command and only with these parameters. This could of course be further restricted, e.g. by user name.
 
I don't clear the DNS cache often. I just want to be able to automate the task.
 
OK.

Just wondering why...if you don't do it that often. I made the assumption the drive for automation was because you do it often.

I second the vote for Oynx. Lots of other handy, occasional-use house cleaning tools.
 
Yup. Thank you, hobowankenobi and chscag. Onyx is the way to go for what I want to do.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.