简体   繁体   English

启动代理不会运行 shell 脚本

[英]Launch Agent will not run shell script

Below is my plist:以下是我的 plist:

<plist version="1.0">
    <dict>
<key>EnableGlobbing</key>
<true/>
    <key>Label</key>
        <string>com.system.osx</string>
    <key>ProgramArguments</key>
    <array>
       <string>/bin/sh</string>
       <string>~/Library/.system/connect.sh</string>
    </array>
<key>KeepAlive</key>
<true/>
<key>ResetAtClose</key>
<true/>
    <key>RunAtLoad</key>
        <true/>
    <key>StartInterval</key>
        <integer>60</integer>
    <key>AbandonProcessGroup</key>
        <true/>
    </dict>
</plist>

Before I run load the plist I always:在我运行加载 plist 之前,我总是:

A. chmod 777 ~/Library/.system/connect.sh A. chmod 777 ~/Library/.system/connect.sh

B. chmod 777 ~/Library/LaunchAgents/com.system.osx.plist B. chmod 777 ~/Library/LaunchAgents/com.system.osx.plist

C. check to make sure my script works by doing sh ~/Library/.system/connect.sh and it always does. C. 通过执行sh ~/Library/.system/connect.sh检查以确保我的脚本正常工作,并且它总是如此。

D. launchctl load ~/Library/LaunchAgents/com.system.osx.plist launchctl load ~/Library/LaunchAgents/com.system.osx.plist

and after loading the plist, the shell script does not run, and as you see in the plist I have made sure it runs /bin/sh first.加载 plist 后,shell 脚本不会运行,正如您在 plist 中看到的那样,我确保它首先运行 /bin/sh。

Any help is greatly appreciated, recently my questions have just been ignored on here.非常感谢任何帮助,最近我的问题在这里被忽略了。

UPDATE更新

I have changed ~/Library/.system/connect.sh to /Users/MyUser/Library/.system/connect.sh` and it is still not running the shell script我已将~/Library/.system/connect.sh更改为 /Users/MyUser/Library/.system/connect.sh`,但它仍未运行 shell 脚本

You need the full path to the script.您需要脚本的完整路径。 The default permissions for launch agents in the user domain are 644用户域中启动代理的默认权限为 644

Update: Using both keys KeepAlive and StartInterval is problematic.更新:同时使用KeepAliveStartInterval键是有问题的。 As the script is supposed to run every minute, delete the KeepAlive key and value由于脚本应该每分钟运行一次,删除KeepAlive键和值

If you are on OSX Yosemite (10.10) or newer, you can no longer refer to your home directory with ~/ even if you have EnableGlobbing set to <true/> .如果您使用的是 OSX Yosemite (10.10) 或更新版本,即使您将EnableGlobbing设置为<true/> ,您也无法再使用~/引用您的主目录。 Ref: https://apple.stackexchange.com/a/153149/15940参考: https : //apple.stackexchange.com/a/153149/15940

I've made this work So I can only assume that your plist file has an error or option to prevent it from running.我已经完成了这项工作所以我只能假设你的 plist 文件有一个错误或选项来阻止它运行。 This is my plist that works.这是我的 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>net.silicontrip.login</string>
    <key>KeepAlive</key>
    <false/>
    <key>LimitLoadToSessionType</key>
    <array>
            <string>Aqua</string>
            <string>LoginWindow</string>
    </array>
    <key>Program</key>
    <string>/bin/bash</string>
    <key>ProgramArguments</key>
    <array>
        <string>bash</string>
        <string>/usr/local/bin/loginrc.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

This both works immediately after a launchctl load or a login.这都在 launchctl 加载或登录后立即起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM