Hi there,
I have a shell script that uninstalls a specific program -- it kills the process if the app is running, looks in three different directories for anything related to the file and deletes them.
When ran from terminal (if the .sh is on the users desktop for example), the script runs completely fine and removes the app as i'd expect it to.
When i add it into Jamf, and launch the Policy I get an error:
Script exit code: 2
Line 55: Syntax error near unexpected token 'fi'
Line 55: 'fi'
Not too sure how the fi on line 55 is wrong, especially if the script runs without error when manually run. I've ensured that I have the Script Content in Jamf set to "Shell" as well... Any suggestions?
Heres the script (Line 55 is the very last line, closing the initial IF statement):
#!/bin/sh
PUBLIC_THUMBPRINT="$1"
if [ $# -eq 0 ]; then
echo "Searching for installed Control clients..."
PUBLIC_THUMBPRINTS=$(ls /opt/ | grep -o -w -E "connectwisecontrol-[[:alnum:]]{16}" | grep -Eo ".{16}$")
PUBLIC_THUMBPRINTS_ARR=($PUBLIC_THUMBPRINTS)
if [ ${#PUBLIC_THUMBPRINTS} -eq 0 ] ; then
echo
echo "No Control clients found!"
echo "Terminating cleanup"
exit
else
echo "Found client(s) with the following public thumbprint(s):"
echo
echo "$PUBLIC_THUMBPRINTS"
echo "Beginning cleanup..."
fi
for thumbprintKey in "${!PUBLIC_THUMBPRINTS_ARR[@]}" ; do
THUMBPRINT="${PUBLIC_THUMBPRINTS_ARR[$thumbprintKey]}"
echo "Unloading client launch agents ($THUMBPRINT)..."
NAMES_OF_USERS_STR2=$(ps aux | grep $THUMBPRINT | grep -Eo '^[^ ]+')
NAMES_OF_USERS_ARR2=($NAMES_OF_USERS_STR2)
for key2 in "${!NAMES_OF_USERS_ARR2[@]}" ; do
POTENTIAL_USER2="${NAMES_OF_USERS_ARR2[$key2]}"
if [ $POTENTIAL_USER2 != "root" ] ; then
NON_ROOT_USER_ID2=$(id -u $POTENTIAL_USER2)
echo "Unloading client launch agent for user $POTENTIAL_USER2"
launchctl asuser $NON_ROOT_USER_ID2 launchctl unload /Library/LaunchAgents/connectwisecontrol-$THUMBPRINT-onlogin.plist >/dev/null 2>&1
fi
done
echo "Unloading client launch daemon ($THUMBPRINT)..."
launchctl unload "/Library/LaunchDaemons/connectwisecontrol-$THUMBPRINT.plist" >/dev/null 2>&1
echo "Deleting client launch agents ($THUMBPRINT)..."
rm "/Library/LaunchAgents/connectwisecontrol-$THUMBPRINT-onlogin.plist" >/dev/null 2>&1
rm "/Library/LaunchAgents/connectwisecontrol-$THUMBPRINT-prelogin.plist" >/dev/null 2>&1
echo "Deleting client launch daemon ($THUMBPRINT)..."
rm "/Library/LaunchDaemons/connectwisecontrol-$THUMBPRINT.plist" >/dev/null 2>&1
echo "Deleting client installation directory ($THUMBPRINT)..."
rm -rf "/opt/connectwisecontrol-$THUMBPRINT.app/" >/dev/null 2>&1
done
echo "Cleanup complete!"
exit
fi
fi