[英]Mac run shell script startup
我有一個plist文件,應該在啟動時啟動shell腳本。
<?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.app.localclient</string>
<key>Program</key>
<string>~/Documents/Local_client/Server.sh</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
我已經將plist文件保存為com.app.localclient.plist
,並測試了可以正常工作的shell腳本。 當我嘗試使用launchctl load com.app.localclient.plist
加載腳本時,它將加載plist但不會啟動shell腳本。 我也將Program參數~
更改為/Users/username/
,但沒有成功。 有沒有一種方法可以使plist啟動Shell腳本,並且可以在不知道腳本保存位置的用戶名的情況下完成此操作(因此,請在路徑中使用〜)。
也許嘗試運行一個shell,因為它將知道您的$ HOME:
<key>ProgramArguments</key>
<array>
<string>bash</string>
<string>-c</string>
<string>"$HOME/Documents/Local_client/Server.sh"</string>
</array>
為了進行調試,請嘗試:
<key>ProgramArguments</key>
<array>
<string>bash</string>
<string>-c</string>
<string>"echo hi > /tmp/DEBUG.txt"</string>
</array>
然后查看/tmp/DEBUG.txt
存在。 如果可行,請嘗試制作最后一個字符串
"/usr/bin/whoami > /tmp/DEBUG.txt"
然后查看/tmp/DEBUG.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.