Skip to main content

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.

Apparently I turned the following option off at some point which causes this behavior.



From:mm2270 on https://jamfnation.jamfsoftware.com/discussion.html?id=7649



There's already an option in the JSS for that (globally) Look under:
Settings > Computer Management Framework Settings > Login and Logout Hooks
Check an option called "Perform login actions in background" I believe that will resolve your issue.