Skip to main content
Question

Automate Site Creation


RDowson
Forum|alt.badge.img+9

I have around 300 sites that I need to create. Is there a way that I can automate this?

5 replies

Hugonaut
Forum|alt.badge.img+15
  • Esteemed Contributor
  • 574 replies
  • April 16, 2019

I believe you can do this with The Mut! Basically create a spreadsheet with the site names and the site flag and upload it to your jamf server.

https://jssmut.weebly.com/

here is the github: https://github.com/mike-levenick/mut you can find some good examples here for what you need to do.


stevewood
Forum|alt.badge.img+35
  • Employee
  • 1797 replies
  • April 16, 2019

I do not believe MUT will create sites. It will allow you to assign Macs to sites by ID or by name.

To do what you want, you'll probably need to us the API. You'll need a CSV file with just the site names in it, then the following should work:

#!/bin/sh
args=("$@")
jssAPIUsername='a-user-with-write-permissions'
jssAPIPassword='the-password'
jssAddress="https://your.jps.com"
file="${args[0]}"

#Verify we can read the file
data=`cat $file`
if [[ "$data" == "" ]]; then
    echo "Unable to read the file path specified"
    echo "Ensure there are no spaces and that the path is correct"
    exit 1
fi

file_length=`awk -F, 'END {printf "%s
", NR}' $file`
counter="0"

while [ $counter -lt $file_length ]
do
    counter=$[$counter+1]
    line=`echo "$data" | head -n $counter | tail -n 1`

    site_name=`echo "$line" | awk -F , '{print $1}'`

    xml="<site><name>${site_name}</name></site>"

    output=`curl -ku ${jssAPIUsername}:${jssAPIPassword} "$jssAddress/JSSResource/sites/id/0" -X POST -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?>$xml"`

done
exit 0

Test this with one or two sites in a file.

HTH


RDowson
Forum|alt.badge.img+9
  • Author
  • Contributor
  • 31 replies
  • April 16, 2019

Thanks!

Where do I place the file and how do I point the script to it?


stevewood
Forum|alt.badge.img+35
  • Employee
  • 1797 replies
  • April 16, 2019

@RDowson sorry, forgot that piece of info. ;-)

Save the script anywhere you want, maybe your home folder. Save the list to the same place. Then you would invoke the script like this:

~/createSites.sh <listfilename>

Make sense?


RDowson
Forum|alt.badge.img+9
  • Author
  • Contributor
  • 31 replies
  • April 17, 2019

That makes sense, thanks.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings