简体   繁体   English

Bash Shell脚本IF语句中的错误

[英]Error in Bash Shell Script IF Statement

I'm trying to get this to run as a launchd, I have setup the plist and enabled the watch path to check when students modify Remote Management. 我试图让它作为启动运行,我已经设置了plist并启用了监视路径以检查学生何时修改远程管理。

I want an if statement that checks to see if the ARD agent is running and of not runs the kickstart command. 我想要一条if语句,以检查ARD代理是否正在运行,而没有运行kickstart命令。

When the service is not running it works perfectly. 当服务未运行时,它可以完美运行。 but when the service is already running I get this error 但是当服务已经在运行时,我得到这个错误

/Users/user/Desktop/test.sh: line 3: [[: 14682  0   com.apple.RemoteDesktop.agent: syntax error in expression (error token is "0    com.apple.RemoteDesktop.agent")

Here is the script; 这是脚本;

#!/bin/bash

if [[ $(launchctl list | grep '^\d.*RemoteDesktop.*') -eq "" ]]; then
    sudo    sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -users admin -access -on -privs -all
else
    exit 0
fi

If anyone could help it would be much appreciated. 如果有人可以帮助,将不胜感激。

You could use quotes and write "$(launchctl list ...)" , but it's probably cleaner to do: 您可以使用引号并输入"$(launchctl list ...)" ,但是这样做可能更干净:

#!/bin/bash

if ! launchctl list | grep -q '^\d.*RemoteDesktop.*'; then
    sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -users admin -access -on -privs -all
else
    exit 0
fi

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

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