2013-04-02 44 views
2

我試圖安排在OS X山一個簡單的任務獅子10.8.3的launchd作業未能執行exec(3)奇怪的原因:8

launchctl start nextstopsun.helloworld 

命令不執行腳本並拋出一個消息控制檯

4/2/13 9:50:49.663 PM com.apple.launchd.peruser.501[139]: (nextstopsun.helloworld[46729]) Job failed to exec(3) for weird reason: 8 

我的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>nextstopsun.helloworld</string> 
    <key>Program</key> 
    <string>/Users/nextstopsun/Work/scripts/hw.sh</string> 
    <key>StartCalendarInterval</key> 
    <dict> 
     <key>Hour</key> 
     <integer>21</integer> 
     <key>Minute</key> 
     <integer>15</integer> 
    </dict> 
    <key>UserName</key> 
    <string>nextstopsun</string> 
</dict> 
</plist> 

劇本也很簡單

echo "Hello World!" > hw.log 

launchctl在沒有錯誤的情況下加載它。 從shell執行腳本時,它按預期工作。 註銷並重新登錄不起作用。 在Google中找不到任何答案。 什麼是「怪異原因:8」的全部?

回答

8

幾點建議:

  1. 使你的腳本執行(chmod +x <your_script>),或通過bash或SH通過腳本啓動它作爲參數
  2. 最有可能:你的錯誤在你的家當行(#!)不能被launchd識別。嘗試#!/bin/sh#!/bin/bash。請注意,它必須是腳本的第一行。
  3. 第一加載你的工作通過launchctl load <your_plist>。但我認爲你已經完成了這個工作,否則會出現其他錯誤信息。
+1

錯誤8是[ENOEXEC「Exec format error」](https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/intro.2.html),所以這幾乎肯定是你的觀點2,破碎的線路。 –

+0

同意,在第一種情況下錯誤是可能EACCES拒絕「權限」(13) – cody

+0

謝謝,我已經添加shebang行給我的腳本。但現在它只是說,'13年4月3日8:43:39.606 PM com.apple.launchd.peruser.501 [139]:(nextstopsun.helloworld [47898])退出,代碼爲:1' – nextstopsun