Posted on 04-16-2019 11:31 AM
I have around 300 sites that I need to create. Is there a way that I can automate this?
Posted on 04-16-2019 12:00 PM
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.
here is the github: https://github.com/mike-levenick/mut you can find some good examples here for what you need to do.
Posted on 04-16-2019 12:17 PM
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
Posted on 04-16-2019 12:33 PM
Thanks!
Where do I place the file and how do I point the script to it?
Posted on 04-16-2019 01:05 PM
@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?
Posted on 04-17-2019 01:59 AM
That makes sense, thanks.