Posted on 08-02-2022 09:39 AM
Hi, I'm having a problem with a simple script to force MS AutoUpdate to list and install any updates.
Script works fine as me locally and via Jamf policy, but doesn't show all the results when pushed via policy to all users.
This is the script:
#!/bin/zsh
echo "Start:" $(date)
#Get current logged on user
currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
#currentUser=$3
echo "User:" $currentUser
#Set Application path
file="/Library/Application Support/Microsoft/MAU2.0/Microsoft AutoUpdate.app/Contents/MacOS/msupdate"
#if test -f "$FILE"; then
if [ -f "$file" ]; then
echo "Application: Exists"
pkill msupdate
#Use the currentUser to run Microsoft's Update application
list=$( sudo -u "$currentUser" "$file" --list | tail -1 )
echo "List:" $list
if [ "$list" != "No updates available" ]; then
install=$( sudo -u "$currentUser" "$file" --install | tail -1 )
echo "Installed:" $install
fi
fi
echo "Finish:" $(date)
My output:
Start: Tue 2 Aug 2022 17:21:02 BST
User: stephen
Application: Exists
List: No updates available
Finish: Tue 2 Aug 2022 17:21:18 BST
All other users output:
Start: Tue 2 Aug 2022 17:22:02 BST
User: aaaaaa
Application: Exists
List:
Finish: Tue 2 Aug 2022 17:22:02 BST
Notice, no output for List: & Start/Finish times are the same - which makes me think it's not running the sudo commands.
Thanks for your help
08-02-2022 10:28 AM - edited 08-02-2022 10:29 AM
@DTB_Kirky Use of msupdate to manually force updates is no longer the recommended approach (and frankly it appears that MS doesn't really bother to test that code path these days). Using the automatic update mechanism is much more reliable, and there is now an easy mechanism to defer those updates rather than having them available for install as soon as released: https://www.kevinmcox.com/2021/10/microsoft-now-provides-curated-deferral-channels-for-autoupdate/
Posted on 08-02-2022 10:33 AM
Yeah I get that, but most of my users don't stay online long enough to see the updates. Hence the script to force them.
This is more of a question as to why the script only works for one person (me)?? and not so much the mechanics of msupdate
08-02-2022 12:21 PM - edited 08-02-2022 12:22 PM
@DTB_Kirky I don't expect the automatic update process would take any longer to detect updates were available than it would for the jamf binary to trigger a checkin to run an update policy, but if you're set on that approach are you sure someone is logged in on your test machine? msupdate has limitations on what context it'll run in. You might want to refer to @pbowden 's old MSUpdateTrigger script to see how it checked for that: https://github.com/pbowden-msft/msupdatehelper/blob/master/MSUpdateTrigger.sh
Posted on 08-03-2022 06:35 AM
You should try the one-liner for zsh presented in Scripting OS X:
currentUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )