Posted on 10-10-2011 08:15 AM
Hi All,
I have some scripts that in the JSS i give values various parameters.
Set timezone being one, so $4 is my time zone which via Remote works by entering Europe/London, but when entering this value in the JSS for use in imaging i get & error.
It looks like the variable value is not passing correctly, does it need to be single quoted or something?
Posted on 10-10-2011 12:20 AM
Thanks guys.
The space was messing it up... (i think it's as a space is not a null value.. & later it was checking for null).
The other script was also wrong due to my fat fingers of fury!!
So yea, pebcak... With me being the one in the chair.
Move along, nothing to see here.
Regards,
Ben.
Posted on 10-10-2011 08:19 AM
How is it being set to $4? In the script?
Posted on 10-10-2011 08:24 AM
script below.. (in this case it's $5).. & looks like it has an extra space.. so am retrying now with a corrected script.
# HARDCODED VALUES ARE SET HERE
timeServer=""
timeZone=" "
# CHECK TO SEE IF A VALUE WAS PASSED IN PARAMETER 4 AND, IF SO, ASSIGN TO "timeServer"
if [ "$4" != "" ] && [ "$timeServer" == "" ];then
timeServer=$4
fi
if [ "$5" != "" ] && [ "$timeZone" == "" ]; then
timeZone=$5
fi
####################################################################################################
#
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
####################################################################################################
OS=/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,4)}'
if [ "$timeServer" != "" ]; then
if [[ "$OS" < "10.5" ]]; then
echo "Setting network time server to: $timeServer..."
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setnetworktimeserver $timeServer
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -setusingnetworktime on
else
echo "Setting network time server to: $timeServer..."
/usr/sbin/systemsetup -setnetworktimeserver $timeServer
/usr/sbin/systemsetup -setusingnetworktime on
fi
else
echo "Error: The parameter 'timeServer' is blank. Please specify a time server."
fi
sleep 5
OS=/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,4)}'
if [ "$timeZone" != "" ]; then
if [[ "$OS" < "10.5" ]]; then
echo "Setting time zone for OS $OS..."
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/systemsetup -settimezone "$timeZone"
echo "Refreshing the clock in the Menu Bar..."
/usr/bin/killall SystemUIServer
else
echo "Setting time zone for OS $OS..."
/usr/sbin/systemsetup -settimezone "$timeZone"
echo "Refreshing the clock in the Menu Bar..."
/usr/bin/killall SystemUIServer
fi
else
echo "Error: The parameter 'timeZone' is blank. Please specify a valid time zone."
fi
Posted on 10-10-2011 11:14 AM
Ben,
This doesn't explain how $4 or $5 are being set, but a quick glance over, do you mean to set timeZone as:
timeZone=" "
and not
timeZone=""
This may explain why the $5 version isn't working.
For your info, the following doesn't have as much overhead as the line you are using:
/usr/bin/sw_vers -productVersion | cut -d "." -f 1,2
instead of
/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,4)}'
'awk' is actually a quite extensive program and your program will break if Apple were to ever get to 10.10, whilst the 'cut' above will continue to work unless apple change the separator (which is unlikely).
Sean
Posted on 10-10-2011 11:32 AM
The script assigns it, basically it makes sure the value is not blank and then assigns it to $4, which is not my preferred method of doing something to be honest.
Also for product version, even more simple and less code instead of putting it into a bunch of if/thens and comparing it to a value.
case `sw_vers -productVersion`
10.5* )) `/some/command -option`;; 10.6* )) `/some/command -option`;; 10.7* )) `/some/command -option`;; esac
my 2 cents
-Tom