Running into a new one - think I've just never hit this combination of issues before.
Have a script that works 100% when run locally, essentially to modify my /etc/hosts file. When run locally, it obviously requires sudo.
When I run it via Jamf, it fails, but I have next to no feedback in my logs other than failure, with the following details:
Executing Policy Fix host (edit /etc/hosts) Checking for patches... No patch policies were found.
Script itself is below - any advice appreciated. Again, works perfectly when run locally if I hard-code the variables, but no feedback when run locally other than "failed"
#!/bin/bash
# adapted from https://gist.github.com/irazasyed/a7b0a079e7727a4315b9
# PATH TO YOUR HOSTS FILE
HOSTS=/etc/hosts
# DEFAULT IP FOR HOSTNAME
IP=$4
# Hostname to add.
HOSTNAME=$5
# Add host
HOSTS_LINE="$IP $HOSTNAME"
if [ -n "$(grep $HOSTNAME $HOSTS)" ]
then
echo "$HOSTNAME already exists"
else
echo "Adding $HOSTNAME to your $HOSTS";
echo $HOSTS_LINE | tee -a $HOSTS;
if [ -n "$(grep $HOSTNAME $HOSTS)" ]
then
echo "Host was added succesfully: $(grep $HOSTNAME $HOSTS)";
else
echo "Failed to Add $HOSTNAME, Try again!";
fi
fi
exit 0