我一直在尝试设置 Launchd 以阻止 osX 10.11.6 上的多个网站
该脚本似乎没有在预定时间内执行。
奇怪的是,launchd 似乎在我加载 plist 时执行命令,但在预定时间内不执行命令。/etc/hosts 已更新为要阻止的站点,但网站未被阻止。
奇怪的是,launchd 似乎在我加载 plist 时执行命令,但在预定时间内不执行命令。
一些谷歌搜索建议我可能需要重置 DNS 缓存:
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder
当我从命令行运行它时,我仍然可以访问应该被阻止的站点。如果要工作,我也不知道如何将其添加到已启动的 plist 程序参数中。
$ cat /Library/LaunchDaemons/local.hosts.blockingAM.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.hosts.blockingAM</string>
<key>ProgramArguments</key>
<array>
<string>cp</string>
<string>/etc/hosts_BLOCKED_sites.txt</string>
<string>/etc/hosts</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>8</integer>
<key>Minute</key>
<integer>15</integer>
<key>Weekday</key>
<integer>1</integer>
</dict>
<dict>
<key>Hour</key>
<integer>8</integer>
<key>Minute</key>
<integer>15</integer>
<key>Weekday</key>
<integer>2</integer>
</dict>
<dict>
<key>Hour</key>
<integer>9</integer>
<key>Minute</key>
<integer>35</integer>
<key>Weekday</key>
<integer>3</integer>
</dict>
<dict>
<key>Hour</key>
<integer>8</integer>
<key>Minute</key>
<integer>15</integer>
<key>Weekday</key>
<integer>4</integer>
</dict>
<dict>
<key>Hour</key>
<integer>8</integer>
<key>Minute</key>
<integer>15</integer>
<key>Weekday</key>
<integer>5</integer>
</dict>
</array>
<key>StandardErrorPath</key>
<string>/tmp/local.hosts.blocking.err</string>
<key>StandardOutPath</key>
<string>/tmp/local.hosts.blocking.out</string>
</dict>
</plist>
以下是权限:
$ ls -la /Library/LaunchDaemons/local.hosts.blockingAM.plist
-rw-r--r--@ 1 root wheel 1474 Sep 8 09:33 /Library/LaunchDaemons/local.hosts.blockingAM.plist
我加载了 plist:
$ sudo launchctl load /Library/LaunchDaemons/local.hosts.blockingAM.plist
没有记录错误:
$ cat /tmp/local.hosts.blocking.err
这是包含被阻止站点的文件:
$ cat /etc/hosts_BLOCKED_sites.txt
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
# Blocked sites redirected to 0.0.0.0
0.0.0.0 reddit.com www.reddit.com
0.0.0.0 facebook.com www.facebook.com
我究竟做错了什么?