To eliminate the possibility that cat'ing a file into your array is the problem, populate the array with simple list of two or three computer names and try again like so:
#!/bin/bash
# Delete computers from JSS based on the file with the list of computer names
jamfUsername="*********"
jamfPassword="*********"
jamfBaseURL="*********"
jamfComputerResource="JSSResource/computers"
# computerList=`cat /file/path/ADtermedmachines.txt`
# arr=($computerList)
arr=(
test-mac-chi1
test-mac-chi2
test-mac-chi
)
for i in "${arr[@]}"; do
echo "Deleting computer: $i"
curl -H "Accept: application/xml" -sfku "$jamfUsername:$jamfPassword" "$jamfBaseURL/$jamfComputerResource/name/$i" -X DELETE
done
If that works, then you might need to do something like the following:
computerList="/file/path/ADtermedmachines.txt"
declare -a arr
# Allows you to comment out lines with '#'
IFS=$'
' arr=("$(grep -v '^#' "$computerList")")
You might also have to delete the computer using the ID of the device, not the name. In that case you can do this:
#!/bin/bash
# Delete computers from JSS based on the file with the list of computer names
jamfUsername="*********"
jamfPassword="*********"
jamfBaseURL="*********"
jamfComputerResource="JSSResource/computers"
computerList=`cat /file/path/ADtermedmachines.txt`
arr=($computerList)
for i in "${arr[@]}"; do
id=$(curl -H "Accept: application/xml" -sfku "$jamfUsername:$jamfPassword" "$jamfBaseURL/$jamfComputerResource/name/$i" | xmllint --xpath xmllint --xpath '/computer/general/id/text()' - 2>/dev/null)
if [[ -z "$id" ]]; then
echo "Could not determine $i's Jamf Pro ID; skipping."
else
echo "Deleting computer: $i"
curl -H "Accept: application/xml" -sfku "$jamfUsername:$jamfPassword" "$jamfBaseURL/$jamfComputerResource/id/$id" -X DELETE
fi
done
@ryan.ball , thank you so much for your input!
You were right, the issue is with cat'ing the file into the array. It worked no problem when I simply created an array with machines within the script.
I have tried your approach:
computerList="/home/akamenevadmin/ADtermedmachines.txt"
declare -a arr
# Allows you to comment out lines with '#'
IFS=$'
'
arr=("$(grep -v '^#' "$computerList")")
for i in "${arr[@]}"; do
echo "arr value is: $i"
done
And it does read the file, but it seems like the whole list of computers is captured as 1 "thing".
The output I got with a simple for loop is:

I am having hard time understanding what "grep" is exactly doing here:
# Allows you to comment out lines with '#'
IFS=$'
'
arr=("$(grep -v '^#' "$computerList")")
IFS part is understood, but the ' -v "^#" ', is not, as I understand it should separate out each line into an array (arr), -v - selecting non-matching lines, ^ - character not in the list, should there be a '#' added in a separate line after each computer name? Sorry if I sound confusing, I am not a big expert in bash scripting.
The grep -v will remove any lines in your list that start with a # symbol so you can comment some things out. I didn't really test out what I send you before, I just pulled it from one of my scripts where I knew I had the same issue during testing.
Does this work for you?
#!/bin/bash
computerList="/home/akamenevadmin/ADtermedmachines.txt"
IFS=$'
'
while read -r i; do
echo "arr value is: $i"
done <<< "$(grep -v '^#' "$computerList")"
@ryan.ball , ah I see, makes sense. Yep, it is fully working with while loop. Thank you man, would take me a while to figure this out :)