Ho bisogno di eseguire uno script in intervalli che richiede l'esecuzione di un utente root. Ho creato un plist che chiamerà uno script in ~/bin/test.sh
.
user@MBP:~$ ls -lah ~/bin/
-rw-r--r-- 1 root staff 566B Feb 6 23:44 test.plist
-rwxr-xr-x 1 root staff 51B Feb 6 23:38 test.sh
Ecco i contenuti:
user@MBP:~$ cat ~/bin/test.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>com.test.script</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>/Users/user/bin/test.sh</string>
</array>
<key>StartInterval</key>
<integer>30</integer>
</dict>
</plist>
user@MBP:~$ cat ~/bin/test.sh
#!/bin/sh
cp /Users/user/bin/dummy.txt /etc
Poi ho collegato un link simbolico al plist in /Library/LaunchAgents
.
user@MBP:~$ ls -lah /Library/LaunchAgents/
lrwxr-xr-x 1 root wheel 31B Feb 5 06:28 com.test.script.plist -> /Users/user/bin/test.plist
Ma tutto questo non funziona. Quando guardo /var/logs/system.log
, dico solo:
Feb 7 14:42:12 MBP com.apple.launchd.peruser.501[242] (com.test.script'[925]): Exited with code: 1