0
我一直在嘗試使用launchD來每24小時執行一次腳本,但是我一直接收奇怪的原因錯誤:2;我知道這意味着該文件沒有找到,但我檢查並進行了雙重檢查,以確保程序參數中的文件路徑是正確的。當我在終端中執行腳本時,腳本運行良好。任何想法爲什麼這不起作用?LaunchD Job失敗的怪異原因:2
該腳本只是從AngelList中刪除新添加的啓動信息並通過電子郵件發送出去。
下面是我的launchd和Python腳本:
Python:
#!/opt/local/bin/python2.6
import urllib
import json
import datetime
import ast
import time
import smtplib
from pymongo import MongoClient
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
... #code omitted
def find_data():
client = MongoClient()
client = MongoClient('localhost', 27017)
db = client.tiger_labs
collection = db.new_startups
existing_names = []
for startup in collection.find():
existing_names.append(startup.get('name')) # inserts all "already-found" startups to the database
market_tags = ["mobile health", "health care", "health care information technology", "health and wellness", "personal health"] # lists out all tags
... # code omitted
text += "</html>"
if text != "<html></html>": # sends e-mail if not empty
nathan = "[email protected]"
tigerlabs = "****@tigerlabs.co, *****@tigerlabs.co"
msg = MIMEMultipart('alternative')
msg['Subject'] = "New Startups"
msg['From'] = nathan
msg['To'] = tigerlabs
part1 = MIMEText(text, 'html')
msg.attach(part1)
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login("[email protected]", "******")
server.sendmail(nathan, tigerlabs, msg.as_string())
server.quit()
print "sent"
else: # purely for testing reasons; wanted to see if launchD was executing
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login("[email protected]", "*********")
server.sendmail("[email protected]", "*****@princeton.edu", "Hi it worked.")
server.quit()
print "not_sent"
find_data()
LaunchD:
<?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.tigerlabs.TigerLabs</string>
<key>ProgramArguments</key>
<array>
<string>/Users/nathanlam/Desktop/Programming_Labs/Coding/TigerLabs.py</string>
</array>
<key>StartInterval</key>
<integer>86400</integer>
<key>KeepAlive</key>
<dict>
<key>NetworkState</key>
<true />
</dict>
<key>StandardErrorPath</key>
<string>/tmp/test.stderr</string>
</dict>
</plist>
'/ usr/include/sys/errno.h'中的2是'ENOENT',即'沒有這樣的文件或目錄' –