Help with an extension attribute please

howie_isaacks
Valued Contributor II

I am working on an extension attribute to check if Aternity is installed, running, and its version. I have to write it this way to take into account the two possible install paths for the agent while we roll out the newer version. I keep running into an error "CFBundleShortVersionString", Does Not Exist". This is being generated from the version check in my script. I have visually confirmed that "CFBundleShortVersionString" DOES EXIST!!! I can run the command in Terminal: 

version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' /Applications/AternityAgent.app/Contents/Info.plist)

When I type echo $version, I get the correct result.

Only when I run the whole script in either Terminal or CodeRunner does it give me that error. Here's my EA. What am I doing wrong?

 

#!/bin/zsh


# Is Aternity installed? Is it the older version or the newer version?
agentOld=(/Library/Aternity/Agent)
agentNew=(/Applications/AternityAgent.app)

if [[ -d $agentOld ]] || [[ -d $agentNew ]]; then
Installed="Installed: Yes"
	if [[ $agentOld ]]; then
	version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' /Library/Aternity/Agent/Contents/Info.plist)
	proc=$(ps axc | /usr/bin/grep -ci "AternityAgent" 2>/dev/null)
		if [ -z "$proc" ];then
		procRunning="Process Running: No"
		else
		procRunning="Process Running: Yes"
		fi
	
	elif [[ -d $agentNew ]]; then
	version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' /Applications/AternityAgent.app/Contents/Info.plist)
	proc=$(ps aux | grep "AternityEUE" | /usr/bin/awk '{print $2}')
		if [ -z "$proc" ];then
		procRunning="Process Running: No"
		else
		procRunning="Process Running: Yes"
		fi
	else
	Installed="Installed: No"
	fi
fi

# Results
echo "<result>$(printf '%s\n' "$Installed" "$procRunning" "Version: $Version")</result>"

 

 

1 ACCEPTED SOLUTION

howie_isaacks
Valued Contributor II

I think I've got it! I tested it in CodeRunner and the results were what I expected to see. I am running the newer version of Aternity. I overcomplicated this at first. CodeRunner and Terminal were confused about which version of the agent was true so they errored out on the CFBundleShortVersionString. The EA displays properly in Jamf Pro.

#!/bin/zsh

# What version Aternity installed? Is it the older version or the newer version?
agentOld=(/Library/Aternity/Agent)
agentNew=(/Applications/AternityAgent.app)

	if [[ -d $agentOld ]]; then
	Installed="Installed: Yes"
	Version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' /Library/Aternity/Agent/Contents/Info.plist)
	proc=$(ps axc | /usr/bin/grep -ci "AternityAgent" 2>/dev/null)
		if [ -z "$proc" ];then
		procRunning="Process Running: No"
		else
		procRunning="Process Running: Yes"
		fi
	
	elif [[ -d $agentNew ]]; then
	Installed="Installed: Yes"
	Version=$(defaults read "/Applications/AternityAgent.app/Contents/Info.plist" CFBundleShortVersionString)
	proc=$(ps aux | grep "AternityEUE" | /usr/bin/awk '{print $2}')
		if [ -z "$proc" ];then
		procRunning="Process Running: No"
		else
		procRunning="Process Running: Yes"
		fi
	else
	Installed="Installed No"
fi

# Results
echo "<result>$(printf '%s\n' "$Installed" "$procRunning" "Version: $Version")</result>"

 

View solution in original post

4 REPLIES 4

mark_lynch
New Contributor III

At a glance (I could be wrong), the first check between $agentOld and $agentNew is checking if either is true, and because of that it's proceeding with the next line (appearing to be line 10. This is resulting in that check occurring regardless if $agentOld is actually installed. Because it's checking either if true, it's carrying on to check the old without a care in the world if it is actually installed, because the second criteria $agentNew was found.

As an aside, I also noticed that the $Version variable in the last line is capitalized whereas the version variable being set is not.

I caught the capitalized issue with "$Version" and corrected it. I wish that was the cause of the issue. Checking if $agentOld or $agentNew is true is intentional. I don't know what version of Aternity will be installed on the Mac that is running the inventory. Because of this, I have to check both install paths. If either is true, then Installed="Installed: Yes". I cannot figure out why all of a sudden I see this error when I created 4 other EAs earlier this week that all used the exact same version check command all looking at "CFBundleShortVersionString" and they worked. I just tested one of those EAs in CodeRunner and it now shows that error. I think I'm going insane.

You were right to zero in on the check between $agentOld and $agentNew. I guess I wrote that wrong. If I remove that section of the script and allow the script to check the version of only the new agent, the version check command works. I think the script doesn't know which install path to check so it errors out. I need a way to allow the script to check both install paths and choose which one is the valid one and perform the version check.

howie_isaacks
Valued Contributor II

I think I've got it! I tested it in CodeRunner and the results were what I expected to see. I am running the newer version of Aternity. I overcomplicated this at first. CodeRunner and Terminal were confused about which version of the agent was true so they errored out on the CFBundleShortVersionString. The EA displays properly in Jamf Pro.

#!/bin/zsh

# What version Aternity installed? Is it the older version or the newer version?
agentOld=(/Library/Aternity/Agent)
agentNew=(/Applications/AternityAgent.app)

	if [[ -d $agentOld ]]; then
	Installed="Installed: Yes"
	Version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' /Library/Aternity/Agent/Contents/Info.plist)
	proc=$(ps axc | /usr/bin/grep -ci "AternityAgent" 2>/dev/null)
		if [ -z "$proc" ];then
		procRunning="Process Running: No"
		else
		procRunning="Process Running: Yes"
		fi
	
	elif [[ -d $agentNew ]]; then
	Installed="Installed: Yes"
	Version=$(defaults read "/Applications/AternityAgent.app/Contents/Info.plist" CFBundleShortVersionString)
	proc=$(ps aux | grep "AternityEUE" | /usr/bin/awk '{print $2}')
		if [ -z "$proc" ];then
		procRunning="Process Running: No"
		else
		procRunning="Process Running: Yes"
		fi
	else
	Installed="Installed No"
fi

# Results
echo "<result>$(printf '%s\n' "$Installed" "$procRunning" "Version: $Version")</result>"