Setting the following variable to gather the user logging in and utilizing it via sudo used to work. The command now reports the console user as root. I have no idea when the behavior changed. When I setup the script initially it was working fine. That was Casper ver 9.1. Now at 9.22 it doesn't work. I have no idea if it is related to the release version or not.
consoleuser=ls -l /dev/console | /usr/bin/cut -d " " -f 4
/usr/bin/sudo -u $consoleuser CMDHERE
before this would result in:
/usr/bin/sudo -u johndoe CMDHERE
now it results in:
/usr/bin/sudo -u root CMDHERE
Getting the value for the last logged in user out of com.apple.loginwindow.plist gets the last logged in user, not the current. IE, the script is running before com.apple.loginwindow.plist is updated.
Has anyone else seen this? I've seen people recommend using a launch hook. I'd prefer not.