Hi everyone,
I'm looking for some help and/or critique on the script below. I would like to mention that I'm still pretty new to scripting and use shellcheck and explainshell pretty heavily. If anyone has any other resources I could add to my arsenal, it would also be much appreciated.
Now that the PSA is out of the way, I want the script to check if the policy banner has been modified or deleted and if so, display a message and run the policy -event policybanner.
#!/bin/bash
loggedInUser=$(stat -f%Su /dev/console)
# Path to the file you want to monitor
file_path="/Users/$loggedInUser/Library/Security/PolicyBanner.rtfd"
# Get the initial modification time of the file
initial_mtime=$(stat -f %m "$file_path")
#changes permissions of after the packages is installed
chmod -R o+rx /Library/Security/PolicyBanner.rtfd
while true; do
# Sleep for a short duration (e.g., 1 second)
sleep 1
# Get the current modification time of the file
current_mtime=$(stat -f %m "$file_path")
# Compare the current modification time with the initial one
if [ "$current_mtime" -gt "$initial_mtime" ]; then
echo "The Policy Banner has been modified"
jamf policy -event policybanner -verbose
/Library/Application\\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -button1 "OK" -windowType hud -description "Please do not modifiy the policy banner. -TSS" -heading "Policy Banner " -title "Ocado Group" -defaultButton 1 -icon "/Library/Application Support/JAMF/ot.icns"
# Update the initial modification time for the next iteration
initial_mtime="$current_mtime"
elif [ ! -e "$file_path" ]; then
echo "The Policy Banner has been deleted!"
jamf policy -event policybanner -verbose
/Library/Application\\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -button1 "OK" -windowType hud -description "Please do not delete the policy banner. -TSS" -heading "Policy Banner " -title "Ocado Group" -defaultButton 1 -icon "/Library/Application Support/JAMF/ot.icns"
fi
sleep 86400
done