Problem with checkJSSconnection in script

elazer
New Contributor II

Hey! I thought I'd try my luck here as well. Im trying to use checkJSSconnection in a while loop but the computer just get stuck in the loop. This happens after setup assistant is complete and the account is logged in.

Code:

jamf checkJSSConnection -retry 0 >> null
status=$?

until [[ $status == 0 ]]; do
jamf checkJSSConnection -retry 0 >> null
status=$?
echo "$(timestamp) Unable to connect to Jamf, retrying ..." | tee -a $log
/bin/sleep 2
done

The exit code returned is 1, and never stops being 1 so the loop continues forver.

The thing is, I do have connection to jamf. If I start a new terminal window and run checkJSSconnection it will return 0. If I kill the jamf process and rerun the script via manual trigger, checkJSSconnection will return 0 on the first try.

This happens every time I run a new test enrollment via prestage, so its not a one time thing.

If I disconnect my wifi, start the loop and then reconnect the wifi the loops exits as soon as the connection is established, so the code seems to work fine. And also if I run this in the terminal, it returns Status is: 0

jamf checkJSSconnection -retry 0 >> null; status=$?;echo "Status is: $status"

So im not really sure how to proceed. Ideas? I know theres other ways I can check the connection, but now Im too stubborn to let this one go :P

1 ACCEPTED SOLUTION

DBrowning
Valued Contributor II

try using 

 jamf checkJSSConnection -retry 0 > /dev/null 2>&1

View solution in original post

4 REPLIES 4

DBrowning
Valued Contributor II

try using 

 jamf checkJSSConnection -retry 0 > /dev/null 2>&1

elazer
New Contributor II

Do you also happen to have the answer to why I didnt just ask here immediately? :D That seemed to work instantly. Not sure where i got the >> null from now that I think about it. Oh well. Thanks!

sdagley
Esteemed Contributor II

@elazer Here's the wrapper function I wrote for checkJSSConnection to wait for connectivity for a limited amount of time:

 

WaitForJSSConnectivity() { # $1 - number of seconds to try before giving up
	jssCheckResponse=""

	startTime=$(/bin/date '+%s')
	whenToQuit=$(($1 + startTime))
	
	while [ -z "$jssCheckResponse" ]; do
	
		jssCheckResponse=$(/usr/local/jamf/bin/jamf checkJSSConnection | /usr/bin/grep available)
			
		if [ -z "$jssCheckResponse" ]; then
			if [ "$(/bin/date '+%s')" -gt $whenToQuit ]; then
				jssCheckResponse="Failed"
			fi
		else
			jssCheckResponse="Success"
		fi
	done

	echo "$jssCheckResponse"
}

 

Example usage:

 

jssConnection=$(WaitForJSSConnectivity 55)

if [ "$jssConnection" = "Success" ]; then
    echo "JSS reachable, do something requiring connectivity
else
    echo "Could not conenct to JSS, maybe ask the user if the Mac is conencted to the network"
fi

 

elazer
New Contributor II

Thanks, might do something like that.