Skip to main content
Question

Troubleshooting a wifi troubleshooting script


johntgeck
Forum|alt.badge.img+7

Hi there,

Hoping I can entreat the Hive Mind to help me nail down why I'm getting an error in the last part of this script. I'm putting together a self service policy that will run two scripts. One grabs the current computer name as a variable, deletes all the relevant networking plist files in /Library/Preferences/SystemConfiguration, and then renames the computer to its original name. That one is working great.

The second script is where I am having trouble (I split them into two because for no discernible reason, the first part would throw weird errors when they were combined in one script but now it seems to work fine with them separate despite there being no differences in the command statements).

This script creates a new network location, switches to it, and deletes the old one. But I'm having trouble with the last part. I'll include the script below, and the jamf policy log output from a test machine.

#Created by John Geck, 7/21/2023 #Create a new network location and substitute the “CRPUSD” variable below with the name you choose originallocation="$(networksetup -getcurrentlocation)" newlocation="CRPUSD" networksetup -createlocation "$newlocation" populate sleep 5 #Switch to your new location networksetup -switchtolocation "$newlocation" sleep 5 #Delete the original location. This is hard-coded because I couldn't figure out how to call the existing locations and create them as a variable. networksetup -deletelocation "$originallocation" #Wait 15 seconds for network to re-establish itself and run a Jamf Recon sleep 15 jamf recon #Notify user they need to reboot osascript -e 'display alert "Reset Successful" message "Please save any open work and restart your computer."' #END

 

Here's the Jamf Error:

Details [STEP 1 of 5] Executing Policy Reset Network Settings (Test) [STEP 2 of 5] Running script Remove Network Plists (Testing)... Script exit code: 0 Script result: [STEP 3 of 5] Running script Reset Network Location... Script exit code: 0 Script result: populated found it! Could not get current network location ** Error: Unable to access the System Configuration database. is not a network location name. ** Error: The parameters were not valid. Retrieving inventory preferences from https://jss.crpusd.org:8443/... Finding extension attributes... Locating accounts... Locating hard drive information... Locating package receipts... Locating printers... Locating plugins... Searching path: /Library/Internet Plug-Ins Locating applications... Searching path: /System/Applications Gathering application usage information from the JamfDaemon... Searching path: /Applications Locating hardware information (macOS 13.4.1)... Submitting data to https://jss.crpusd.org:8443/... <computer_id>2166</computer_id> button returned:OK [STEP 4 of 5] [STEP 5 of 5]

4 replies

sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • 3540 replies
  • July 21, 2023

@johntgeck I think Jamf will try and run it as a shell script anyways, but you're missing a #!/bin/sh at the beginning of the script you posted.

What does the script return if you try and run in from Terminal? (Use the sudo prefix to run as admin)


Forum|alt.badge.img+8
  • Valued Contributor
  • 109 replies
  • July 23, 2023

@johntgeck I was unable to reproduce this issues however the error it suggests the variable "originallocation" is not being populated.

To help troubleshoot issues remotely, it's best practice to echo out each step and any resulting response. If you're also dependent upon a result, you can ensure it's not empty using a test.

 

# Get Current Location
originallocation="$(networksetup -getcurrentlocation)"
if [ -z $originallocation ]; then
echo "Current Location not found"
else
echo "Current Location is $originallocation"
fi

 


johntgeck
Forum|alt.badge.img+7
  • Author
  • Contributor
  • 44 replies
  • July 24, 2023
jimmy-swings wrote:

@johntgeck I was unable to reproduce this issues however the error it suggests the variable "originallocation" is not being populated.

To help troubleshoot issues remotely, it's best practice to echo out each step and any resulting response. If you're also dependent upon a result, you can ensure it's not empty using a test.

 

# Get Current Location
originallocation="$(networksetup -getcurrentlocation)"
if [ -z $originallocation ]; then
echo "Current Location not found"
else
echo "Current Location is $originallocation"
fi

 


Thanks for the tip, I will definitely make those changes and see what I get.


johntgeck
Forum|alt.badge.img+7
  • Author
  • Contributor
  • 44 replies
  • July 24, 2023
sdagley wrote:

@johntgeck I think Jamf will try and run it as a shell script anyways, but you're missing a #!/bin/sh at the beginning of the script you posted.

What does the script return if you try and run in from Terminal? (Use the sudo prefix to run as admin)


Yeah I wasn't sure if I needed the shebang, I tried with and without and it didn't seem to make a difference. I might as well add it back in. @jimmy-swings also suggested I echo out each step to see where things are going off the rails, so I'll do that as well.

 

It's good to look at this with fresh eyes today, the original impetus to script this was a wireless issue that ended up getting diagnosed as an infrastructure issue, but I like the idea of having this script as a one-button "nuke everything and start with fresh settings" troubleshooter for my field techs.


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