
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 11-27-2012 12:53 AM
Hi,
What i'm trying to do is to run a query in our firstrun script, on the JSS for the Mac it's currently running on. All it's trying to do is to see if the department and building settings are correctly configured. (Our JSS occasionally doesn't configure these fields properly via prestage imaging.) If they are, it skips a section of code that would give a menu choice. Here's what i've got so far (in a highly simplified version):
#!/bin/bash
JSSUSR="x"
JSSPWD="x"
JSSURL=$( /usr/bin/defaults read /Library/Preferences/com.jamfsoftware.jamf.plist jss_url )
JSSPATH="JSSResource/computers/macaddress"
MACMAC=$( networksetup -getmacaddress en0 | awk '{print $3}' | sed 's/:/./g' )
BUILDING=$( curl -s -u $JSSUSR:$JSSPWD $JSSURL$JSSPATH/$MACMAC | xpath //computer/location/building/text | sed -e 's/<building>//;s/</building>//' )
DEPT=$( curl -s -u $JSSUSR:$JSSPWD $JSSURL$JSSPATH/$MACMAC | xpath //computer/location/department/text | sed -e 's/<department>//;s/</department>//' )
if [[ $BUILDING == "" || $DEPT == "" ]] ;
then
*code here*
fi
I've redacted our api readonly account name and password for security.
The idea is that if either or both of the two fields are blank, the script in the if statement should run. If not, it skips and gets on with the rest of the firstrun script.
What actually seems to happen is that the code in the if statement executes regardless! That's not such a bad flaw at this stage, but it's something i'd like to correct. Any thoughts?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 12-12-2012 06:52 AM
Have a look at this: http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/tests.html
It's a great resource.
Here's the front page of the guide http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 11-27-2012 05:37 AM
I think you may want to instead do
if [ -z $BUILDING]
In the database, for that record, if the building or department aren't set, they should be NULL. You can verify this by looking in your database with read-only access and MySQL Workbench. You want to check to see if $BUILDING is NULL, not if it's empty. There's a difference.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 11-27-2012 08:23 AM
That's pretty cool. Is there a way to check if either or both of them is NULL?
e.g.
if [ -z $BUILDING ] || [ -z $DEPT}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 12-11-2012 08:33 AM
Sure can. Except I don't think you want a curly brace at the end there. That'll trip you up for sure.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 12-11-2012 11:23 AM
Double ampersands is the answer here if you want to test two things in a if then statement
if [[ -z var1 ]] && [[ -z var2 ]]
then unix stuff happens here
else we stop or do other Unix stuff
fi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 12-12-2012 06:52 AM
Have a look at this: http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/tests.html
It's a great resource.
Here's the front page of the guide http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 01-19-2013 02:28 PM
We ended up giving up and not using the check after we abandoned all use of prestage imaging configuration. Thanks anyway!
