Reinstall JSS Management

yurypanasyuk
New Contributor III

Hello,

Looking for help on my current bash script to reinstall the JSS management. Everything is working except I cant figure out how to search every line of the output to the command variable.

#!/bin/bash

jss_comm_chk=$(jamf checkJSSConnection& sleep 2; kill $! > /dev/null; echo $?)

if [[ "$jss_comm_chk" == *"JSS is available"* ]]
then
echo "JSS binary already installed. Attempting to reinstall..."
sudo jamf removeFramework
sleep 2
sudo installer -pkg /Library/CE/security/installers/Casper/QuickAdd.pkg -target /
sleep 2
fi

if [[ "$jss_comm_chk" == *"command not found"* ]] #FAILS TO SEARCH HERE
then
echo "JSS binary not currently installed. Attempting to install..."
sudo installer -pkg /Library/CE/security/installers/Casper/QuickAdd.pkg -target /
fi

if [[ "$jss_comm_chk" == *"Waiting 5"* ]]
then
echo "No internet connection. Please connect to any network BESIDES CorpWifi."
fi

This is the output of the variable above where its failing:

[1] 71021
-bash: jamf: command not found
[1]+  Exit 127                jamf checkJSSConnection
-bash: kill: (71021) - No such process
1
8 REPLIES 8

Phantom5
Contributor II

Have you tried using the full path to the jamf binary?

jss_comm_chk=$(/usr/local/jamf/bin/jamf checkJSSConnection& sleep 2; kill $! > /dev/null; echo $?)

That should work for you.

mschroder
Valued Contributor

Hi,

using the full path name is always a good idea. But before using the jamf binary it might also be useful to check whether it exists (and is an executable:

if [ -x /usr/local/jamf/bin/jamf ]; then # it exists, and it is executable, so I can use it :) do nice things with /usr/local/jamf/bin/jamf
else # it's not there, or it is not executable :( echo "I am doomed"
fi

And before removing the existing framework I would check whether the QuickAdd package is indeed on the client. Would be a pity to remove the old framework if the package needed to re-install it is not there...

I have seen several clients on which /usr/local/jamf/bin/jamf did not exist due to some hiccup during the update :(

Hope this helps.

yurypanasyuk
New Contributor III

Thank you guys that helps! @f.deis It doesn't work using full path but I will definitely use it to be safe. What I cant figure out is printing or searching the second line of the output. Thats where it fails. But using @mschroder tip works perfectly! New code below: Feedback welcome =)

#!/bin/bash

jss_comm_chk=$(/usr/local/jamf/bin/jamf checkJSSConnection& sleep 2; kill $! > /dev/null; echo $?)

if [[ "$jss_comm_chk" == *"JSS is available"* ]]
then
echo "JSS binary already installed. Attempting to reinstall..."
sudo jamf removeFramework
sleep 2
sudo installer -pkg /Library/CE/security/installers/Casper/QuickAdd.pkg -target /
sleep 2
fi

if [[ "$jss_comm_chk" == *"Waiting 5"* ]]
then
echo "No internet connection. Please connect to any network BESIDES CorpWireless."
fi

if [ -x /usr/local/jamf/bin/jamf ]
then
:
else
echo "JSS binary not currently installed. Attempting to install..."
fi

yurypanasyuk
New Contributor III

Can anyone help with why I am unable to removeFramework when calling shell script from AppleScript droplet (.app)? It works fine when running from terminal.

Sachin_Parmar
Contributor

@yurypanasyuk - you looked at Casper Agent Check by Rich Trouton? It's well documented and achieves what you want

yurypanasyuk
New Contributor III

Yes I have seen it but it still doesnt solve but I am trying to do. To simplify I tested using AppleScript code below and it errors out with:

"/bin/sh: usr/sbin/jamf: No such file or directory". Running directly from terminal has no issues.

AppleScript:

do shell script "usr/sbin/jamf removeFramework" with administrator privileges

Sachin_Parmar
Contributor

@yurypanasyuk -

#!/bin/sh

#Run System Command to Remove JAMF Framework
sudo /usr/local/bin/jamf removeFramework

Sachin_Parmar
Contributor

@yurypanasyuk -

#!/bin/sh

#Run System Command to Remove JAMF Framework
sudo /usr/local/bin/jamf removeFramework