Saya punya file plist yang disimpan
/Library/LaunchDaemons/local.WiFiDaemon.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<false/>
<key>GroupName</key>
<string>staff</string>
<key>InitGroups</key>
<true/>
<key>Label</key>
<string>local.job</string>
<key>ProgramArguments</key>
<array>
<string>python</string>
<string>/Library/Application Support/PythonDaemons/PythonTest.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/local.job.err</string>
<key>StandardOutPath</key>
<string>/tmp/local.job.out</string>
<key>UserName</key>
<string>myuser</string>
</dict>
</plist>
file seharusnya mengeksekusi skrip python yang hanya ping google dan menyimpan hasilnya ke file teks di:
/Library/Application Support/PythonDaemons/Ping_log.txt
masalahnya adalah skrip python memberikan kesalahan yang mengatakan tidak memiliki izin untuk file tersebut. Ketika saya menjalankan skrip dari baris perintah semuanya berfungsi dengan baik tanpa izin khusus yang diperlukan. Apa yang saya lewatkan di sini?
Berikut skrip python:
import subprocess, datetime, time
host = "www.google.com"
ping = subprocess.Popen(
["ping", "-c", "4", host],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)
out, error = ping.communicate()
with open('PingOut.txt', 'w') as outFile:
outFile.write(out)
temp = out.split('\n')
parsed = temp[len(temp)-2].split('/')
min = parsed[len(parsed)-4].split(' ')[2]
avg = parsed[len(parsed)-3]
max = parsed[len(parsed)-2]
print "min: " + str(min) + "avg: " + str(avg) + "max: " + str(max)
with open('Ping_log.txt', 'a') as f:
f.write(str(datetime.datetime.now()) + ',' + str(min) + ',' + str(avg) + ',' + str(max))
traceback (most recent call last): File "/Library/Application Support/PythonDaemons/PythonTest.py", line 15, in <module> with open('PingOut.txt', 'w') as outFile: IOError: [Errno 13] Permission denied: 'PingOut.txt'
/Library/Application Support/PythonDaemons/
?