Script - Network Locations

ds_support
New Contributor III

Hello,

I need the community

I have a script, which create two Network Locations. The script work but finish with a error. I'm not sure why. Some settings the script add in the new network locations but not the important setting. We need to add the Auto URL Proxy Link.

Can everyone tell me why the script crashed and what I need to add the Proxy URL adress?

Here the script and the error what I get.

Script:

#! /bin/sh

####################################################################################################

#hardcoded variables
usb="USB Ethernet"
display="Display Ethernet"
tbolt="Thunderbolt Ethernet"
wired="Ethernet"
wireless="Wi-Fi"
btDUN="Bluetooth DUN"
btPAN="Bluetooth PAN"
firewire="FireWire"

####################################################################################################

#define proxy servers
proxy="http://proxyconf.xxx.de:8/wpad.dat"

####################################################################################################

#detect network interfaces
usbAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: USB Ethernet"`
displayAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Display Ethernet"`
tboltAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Thunderbolt Ethernet"`
wiredAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Ethernet"`
wifiAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Wi-Fi"`
btDUNAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Bluetooth DUN"`
btPANAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: Bluetooth PAN"`
firewireAdapter=`/usr/sbin/networksetup -listallhardwareports | grep "Hardware Port: FireWire"`


####################################################################################################

#######
#Create new Location "Company_NetWork" with Proxy, Bypass Domains and Search Domain 
#######

networksetup -createlocation "Company_Network" populate

#Switch to Location Client_Net

networksetup -switchtolocation "Company_Network"


##############
## Ethernet ##
##############

if [ "$wiredAdapter" != "" ]; then
/usr/sbin/networksetup -setdhcp "$wired"
/usr/sbin/networksetup -setv6off "$wired"
/usr/sbin/networksetup -setproxybypassdomains "$wired" *.local 169.254/16 whatever.company.net
/usr/sbin/networksetup -setsearchdomains "$wired" dfl.local
fi


#####################
## Wifi ##
#####################

if [ "$displayAdapter" != "" ]; then
/usr/sbin/networksetup -setdhcp "$wireless"
/usr/sbin/networksetup -setv6off "$wireless"
/usr/sbin/networksetup -setproxybypassdomains "$wireless" *.local 169.254/16 whatever.company.net
/usr/sbin/networksetup -setsearchdomains "$wireless" dfl.local
fi


#########################
## Thunderbolt Adapter ##
#########################

if [ "$tboltAdapter" != "" ]; then
/usr/sbin/networksetup -setdhcp "$tbolt"
/usr/sbin/networksetup -setv6off "$tbolt"
/usr/sbin/networksetup -setproxybypassdomains "$tbolt" *.local 169.254/16 whatever.company.net
/usr/sbin/networksetup -setsearchdomains "$tbolt" dfl.local
fi


####################################################################################################

#######
#Create new Location "Home_Network" without any Settings 
#######

networksetup -createlocation "Home_Network" populate

#Switch to Location Client_WIFI

networksetup -switchtolocation "Home_Network"


####################################################################################################

#Switch back to Location Client_Net

networksetup -switchtolocation "Company_Network"

exit 0

The Log:

Sending Wake On LAN command... Opening SSH Connection to 192.168.xx.xx.. Authenticating... Successfully authenticated. Verifying Computer's Identity... The MAC Address has been verified. Checking Operating System Version... Running Mac OS X 10.11.6 (15G31) Verifying /usr/local/jamf/bin/jamf... /usr/local/jamf/bin/jamf is current (9.99.0-t1494340586) Verifying /usr/sbin/jamf... /usr/sbin/jamf does not exist. Verifying /Library/Preferences/com.jamfsoftware.jamf.plist... Preparing Policy... Executing Policy 2017-06-21 at 10:15 AM | | 1 Computer Running script Network Location... Script exit code: 0 Script result: populated found it! ** Error: Unable to commit changes to network database. populated found it! found it! Submitting log to https://casper.xxx.local:8443/ Finished.

Thanks for help!
Chris

4 REPLIES 4

tomgi
New Contributor II

Hello,

First, you can change your shebang to "#!/bin/sh -x" to get verbose mode.

This will show you each line executed before each answer :)

ds_support
New Contributor III
Hello, First, you can change your shebang to "#!/bin/sh -x" to get verbose mode. This will show you each line executed before each answer :)

Thanks it was a great help! The script works now. But Casper tell me a error but all Seetings correct. Why I get this error "found it! ** Error: Unable to commit changes to network database." Not sure why..

Thanks :)

tomgi
New Contributor II

The "Found it!" message is related to "networksetup switchlocation xxx" when the location is found.

We got here a script to create all locations (same build all over the world/languages) and got "Found it!Found it!Found it!Found it! etc" in logs :D

For the error message "Error: Unable to commit changes to network database." it should be a good thing to link the message to the line in your script related to. Until now, I never faced this error message so I don't really know what it could be.

tomgi
New Contributor II

One question still at the end of your script.
Why switching to the Home_Network location without doing anything to get back to Company_Network location just after ?

I'll probably ended my script like this :

#######
#Create new Location "Home_Network" without any Settings 
#######
networksetup -createlocation "Home_Network" populate

exit 0