Script doesn't run via Policy

al786
New Contributor III

I have a script that only runs locally - not via policy. Can anyone tell me what I'm doing wrong?

#!/bin/bash

loggedInUser=$(ls -l /dev/console | awk '{print $3}')

defaults write /Users/$loggedInUser/Library/Preferences/com.microsoft.autoupdate2.plist HowToCheck "Manual"
2 REPLIES 2

amoscaritola
New Contributor III

If you want to enforce the manual check for office updates you can try a custom configuration profile.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>HowToCheck</key>
    <string>Manual</string>
</dict>
</plist>

Look
Valued Contributor III

How are you invoking the policy? If it runs when no one is logged in it will do nothing as $loggedInUser will be empty.
If your running it as Login or Self Service you can use $3 directly as this will contain the username that either logged in or signed into Self Service. Outside of that contect you need to ensure that there is someone logged in.