hello,
I have written a script which executes a policy and uses terminal notifier to notify the user of an installation.
because terminal notifier cannot run during the login window, i check the currently logged in user, if the user is root (assume we are at the login window) , execute the policy and create a text file on the local machine, otherwise we are logged in and run the policy with terminal notifier.
i then have a while loop which checks the existence of such a file and verifies the user is not root and then displays a terminal notifier window.
Executing the script from terminal on the machine works perfectly fine…. however, as soon as I run the script through terminal it runs the script and nothing happens, its almost like it doesn't execute anything. I may be missing something simple here but I have tried to emulate the conditions locally by executing as root in the terminal.
Has anyone seen anything like this before? I am receiving no error logs when the policy runs, the last message I am left with is Running script……. and then it times out.
here is the code:
#!/bin/bash
#Define policy id + policy name pid="3342" policyName="Garageband 10.0.1"
declare -x TERMINALNOTIFIER="/usr/local/scripts/terminal-notifier.app/Contents/MacOS/terminal-notifier"
currentUser=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'
#Now perform the installation based on the current user
if [ $currentUser = "root" ]; then #we are at the login window so we can't run terminal notifier
echo "Installation of $policyName began at" $(date) >> /usr/local/scripts/"$pid".txt /usr/sbin/jamf policy -id "$pid" echo "Installation of $policyname Completed at" $(date) >> /usr/local/scripts/"$pid".txt
else
echo "normal user is logged in, so we can use terminal notifier!"
$TERMINALNOTIFIER -message "Currently Installing $policyName" -title "Application Install In Progress" /usr/sbin/jamf policy -id "$pid" && $TERMINALNOTIFIER -message "Installed $policyName" -title "Application Install Successful"
fi
#check for the presence of the policy file as this is only created if policy is ran at the loginwindow
#if we see it and the user is not root we can open terminal notifier to inform the user of an app install/installation
while [ -f /usr/local/scripts/"$pid".txt ]
do
sleep 30
currentUser=/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'
if [ $currentUser != "root"]
then
#we logged in display a notification
#get the last non empty line of the text file we created
installProgress=$(awk '/./{line=$0} END{print line}' /usr/local/scripts/"$pid".txt)
if [[ $installProgress = *began* ]]
then
/usr/local/scripts/terminal-notifier.app/Contents/MacOS/terminal-notifier -message "Currently Installing $policyName" -title "Application Install In Progress"
else
/usr/local/scripts/terminal-notifier.app/Contents/MacOS/terminal-notifier -message "Installed $policyName" -title "Application Install Successful"
rm /usr/local/scripts/"$pid".txt
exit 0
fi
fi
done