Skip to main content
Question

SetSearchDomain.sh fails when pushed through JSS to OSX 10.7 -10.8

  • July 1, 2013
  • 2 replies
  • 30 views

Forum|alt.badge.img+4

Hi Guys,

So i have a shell script that "should" accommodate for OSX 10.6 -10.8

When I push it through casper to a 10.6.8 box it runs likes like a champ, but i've recently tried pusing it to a 10.8.4 box and it fails with a syntax error.

That being said, if move the script locally onto the 10.8 system, run a chmod and then execute the script in terminal it ran beautifully. The only thing i noticed when I ran it locally was that it prompted for admin credentials. Not in the script, but it actually pormpted a "wants to make changes to your computer" box.

Here is what i'm using... would REALLY appreciate any input on this!

#!/bin/sh

#   setSearchDomains.sh -- Set a search domain for a specified network interface
#
# SYNOPSIS
#   sudo setSearchDomains.sh
#   sudo setSearchDomains.sh <mountPoint> <computerName> <currentUsername> <networkInterface>
#                           <searchDomains> 
#
#   If the $networkInterface parameter is specified (parameter 4), this is the Network Interface for
#   which the search domains will be set.  The expected values for the $networkInterface parameter can
#   be found by running the command:
#
#       networksetup -listallnetworkservices
#
#   If the $searchDomains parameter is specified (parameter 5), this is the search domain that will
#   be set.
#
#   If no parameter is specified for parameters 4 and 5, the hardcoded value in the script will be 
#   used.
#
# DESCRIPTION
#   This script will set a search domain in the network settings for whichever network interface has
#   been specified.
#
#
# DEFINE VARIABLES & READ IN PARAMETERS
#
####################################################################################################


# HARDCODED VALUES ARE SET HERE  Example Interfaces are Ethernet 1, Ethernet 2, Thunderbolt Ethernet (rMBP), USB Ethernet etc basically whatever your Network Type shows in Sys Prefs
networkInterface="Wi-Fi"
searchDomains="Company.corp, americas.company.corp, europe.company.corp, sea.company.corp, asia.company.corp"


# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 4 AND, IF SO, ASSIGN TO "networkInterface"
if [ "$4" != "" ] && [ "$networkInterface" == "" ];then
    networkInterface=$4
fi

# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 5 AND, IF SO, ASSIGN TO "searchDomains"
if [ "$5" != "" ] && [ "$searchDomains" == "" ];then
    searchDomains=$5
fi

####################################################################################################
# 
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
####################################################################################################

if [ "$networkInterface" == "" ]; then
    echo "Error:  No network interface has been specified."
    exit 1
fi

if [ "$searchDomains" == "" ]; then
    echo "Error:  No search domains have been specified."
    exit 1
fi

OS=`/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,4)}'`

if [[ "$OS" < "10.5" ]]; then
    echo "Setting search domains for OS $OS..."
    /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setsearchdomains "$networkInterface" "$searchDomains"
else
    echo "Setting search domains for OS $OS..."
    /usr/sbin/networksetup -setsearchdomains "$networkInterface" "$searchDomains"
fi

Here is what i'm getting from the log

Script Result: /private/tmp/setSearchDomains-WiFi copy.sh: line 1: syntax error near unexpected token `newline'
/private/tmp/setSearchDomains-WiFi copy.sh: line 1: `

2 replies

Forum|alt.badge.img+11
  • Contributor
  • July 1, 2013

I would generally get the "line 1: syntax error near unexpected token `newline'" on a machine that wasn't downloading the script or had share permission issues


Forum|alt.badge.img+7
  • Contributor
  • July 2, 2013

This is the code we use to do our network settings between 10.6 and 10.8, the difference is the "Airport" in 10.6 and in 10.8 its called "Wi-Fi" we dont run Lion so not sure if it will work for that.
We have not spent too much time in getting it to be more efficient but its simple and works. We also have a package which copies in the 802.1x profile for wireless for 10.6 systems which the script imports aswell, we run this script at reboot as 10.8 needs to generate a networkpreferences.plist on first boot.

For 10.7 you might want to add in 10.7 in the first if statement to be included, also if made the places were you need to put in your own settings in bold.

I hope this helps and makes sense.

#!/bin/bash


#############################################################
# Script to push new network settings to client systems
##############################################################

### Set Variable for OS Version
sysver=`sw_vers -productVersion | cut -c 1-4`

echo "  ************************************************"
echo "  * Setting up the Network for " $sysver

### Set Wireless Device based on OS Version
if [ $sysver = 10.6 ]; then
WirelessName="AirPort"
WirelessState=$(/usr/sbin/networksetup -getnetworkserviceenabled AirPort)
elif [ $sysver = 10.8 ]; then
WirelessName="Wi-Fi"
WirelessState=$(/usr/sbin/networksetup -getnetworkserviceenabled Wi-Fi)
fi

echo "  * " $WirelessName "is currently " $WirelessState

### If Wireless is Enabled then configure it
if [ $WirelessState = "Enabled" ]; then
    # 1) Turn off IPv6
    networksetup -setv6off $WirelessName

    # 2) Set the Auto-Proxy script location
    networksetup -setautoproxyurl $WirelessName **http://<proxyurl/proxy.pac>**

    # 3) Set Proxy Bypass Domains
    networksetup -setproxybypassdomains $WirelessName *.local **<set your ip addresses here>**

    # 4) Set connection Search Domains
    networksetup -setsearchdomains $WirelessName **<searchdomain1.com> <searchdomain2.com>**

echo "  * Wireless Adapter Configured"

        ### Do Not Import Profile on Mountain Lion
        if [ $WirelessName = "AirPort" ]; then
            # 5) Set AirPort Preferred Wireless Connection
            networksetup -import8021xprofiles $WirelessName **"/Library/Application Support/<directory name>/Configuration/Wireless.networkconnect" **
        echo "  * Import of Wireless Profile Completed"
        fi
fi

### Configure Ethernet
# 1) Turn off IPv6
networksetup -setv6off "Ethernet"

# 2) Set the Auto-Proxy script location
networksetup -setautoproxyurl "Ethernet" **http://<proxyurl/proxy.pac>**

# 3) Set Proxy Bypass Domains
networksetup -setproxybypassdomains "Ethernet" *.local **<set your ip addresses here>**

# 4) Set connection Search Domains
networksetup -setsearchdomains "Ethernet" **<searchdomain1.com> <searchdomain2.com>**

echo "  * Ethernet Adapter Configured"
echo "  * Network Settings Completed"
echo "  ************************************************"
exit 0