CreateBuildingFromCSV.sh - Jamf API Scripts on GitHub

MatG
Contributor III

There are a bunch of jamf API scripts here:
https://github.com/jamf/API_Scripts

I'm trying to run the CreateBuildingFromCSV.sh but all I get is an error

line 60: [: too many arguments

These have not been updated in years, would nice if Jamf could fix them.

3 REPLIES 3

mpuyet
New Contributor II

Hello you could use that script :

#!/bin/sh
jamfUrl=""
jamfUser=""
jamfPass="" 

#Set my csv location
Building_CSV="$HOME/Desktop/Building.csv"

#For each line of the CSV File
while read line; do 
    #Get the List of existing Building
    Building_Already_Existing=$(curl -sku $jamfUser:$jamfPass  -H "Accept: application/xml" $jamfUrl/JSSResource/buildings | xmllint --format - | grep "<name>" | awk 'BEGIN{FS=">|<"} {printf "%s;", $3}')

    #Check if the Building is not in the existing Building List
    if [[ $Building_Already_Existing != *"$Building_Name;"* ]]; then 
            Echo "Building : $Building_Name : not existing in Jamf, creation !"
            #Create the Building
            curl -sku $jamfUser:$jamfPass  -H "Content-type: application/xml" $jamfUrl/JSSResource/buildings/id/0 -X POST -d "<building><name>$Building_Name</name></building>"
        else
            #Else do nothing
            Echo "Building : $Building_Name : Already exist"
    fi
done < $Building_CSV
exit

MatG
Contributor III

I'll give that ago - thanks :)

SamF
Contributor II
Contributor II

I have updated the script on the Jamf GitHub repo, which should resolve the issue. If there are any additional issues, let me know or open an issue on GitHub. On a related note, I'll be taking a closer look at the other API scripts within that repo in the coming weeks.