Skip to main content
Solved

Problem with checkJSSconnection in script


Forum|alt.badge.img+3

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

Best answer by DBrowning

try using 

jamf checkJSSConnection -retry 0 > /dev/null 2>&1
View original
Did this topic help you find an answer to your question?

DBrowning
Forum|alt.badge.img+24
  • Esteemed Contributor
  • March 13, 2023

try using 

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

sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • March 13, 2023

@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

 


Forum|alt.badge.img+3
  • New Contributor
  • March 13, 2023
DBrowning wrote:

try using 

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

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!


Forum|alt.badge.img+3
  • New Contributor
  • March 13, 2023
sdagley wrote:

@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

 


Thanks, might do something like that.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings