Sto provando a bloccare alcuni siti web tramite / etc / hosts
Non riesco a capire come eseguire LaunchAgent con le autorizzazioni corrette.
$ ls -la ~/Library/LaunchAgents/hosts_Blocksites_AM.plist
-rw-r--r--@ 1 root staff 1854 Aug 25 11:55 /Users/bryanwheelock/Library/LaunchAgents/hosts_Blocksites_AM.plist
Ho impostato un tasto UserName:
<key>UserName</key>
<string>root</string>
Ecco i hosts_Blocksites_AM.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.job</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>UserName</key>
<string>root</string>
<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>8</integer>
<key>Minute</key>
<integer>15</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/mycommand.err</string>
<key>StandardOutPath</key> <string>/tmp/mycommand.out</string>
</dict>
</plist>
Ecco gli errori:
$ cat /tmp/mycommand.err
sudo: no tty present and no askpass program specified
cp: /etc/hosts: Permission denied
Avevo provato ad aggiungere il comando sudo agli argomenti del programma, ma non penso che fosse corretto.
A CURA:
Chiave etichetta modificata:
<key>Label</key>
<string>local.hosts.blockingAM</string>
Chiave UserName rimossa.
Spostato il plist e il nome cambiato:
$ ls -la /Library/LaunchDaemons/
-rw-r--r--@ 1 root wheel 1474 Aug 29 13:19 local.hosts.blockingAM.plist
Stavo ancora ricevendo errori di autorizzazione fino a quando ho lanciato launchctl con sudo:
sudo launchctl load /Library/LaunchDaemons/local.hosts.blocking.plist