Posted on 02-27-2009 06:24 PM
Hi-
Is there a way to run a script as the currently logged in user instead of root? What I want to do is have the software update background check run, do the auto download and then prompt the user that updates are ready for install. I can do this with a script that runs:
cd /System/Library/CoreServices/Software Update.app/Contents/Resources/
./SoftwareUpdateCheck
But, only if you run it as the logged in user. If you run it as root with the agent (or just a sudo on the command line) it's no different than just popping up Software Update and watching it scan for updates. I know it's a minor difference, but I like attention to detail :)
I thought about using sed to pull the current user name from the output of
ls -l /dev/console
And then assigning that to a variable and using sudo -u but I'm not a sed wiz.
Is this the right approach or is there a better way?
---
Jared F. Nichols
Desktop Engineer, Infrastructure and Operations
Information Services Department
MIT Lincoln Laboratory
244 Wood Street
Lexington, Massachusetts 02420
781.981.5436
Posted on 02-27-2009 06:36 PM
I would check the displayMessage verb for the jamf binary.
In your script you do a command:
/usr/sbin/jamf displayMessage -message 'There are Apple updates available for you to install'. This will bring up a dialog window with an OK button to clear for the currently logged on user.
For future reference if you have a script that you will run using the jamf binary with Casper Remote, a policy, etc. if you use $3 I believe that gives you the username of the currently logged on user.
Wonder if that helps out your issue?
Craig Ernst
Systems Management and Configuration
+-------------------+
University of Wisconsin-Eau Claire
Learning and Technology Services
105 Garfield Ave
Eau Claire, WI 54701
Phone: (715) 836-3639
Fax: (715) 836-6001
+-------------------+
ernstcs at uwec.edu
Posted on 02-27-2009 06:47 PM
Hi-
Just figured it out.
Using cut instead of sed was the key. Here's the script. Feel free to recycle (attached too)
#!/bin/sh
################################################################################################
##### Filename: backgroundswupd.sh #####
##### Author: Jared F. Nichols #####
##### Purpose: Trigger the background process to check for and download software updates #####
##### as the currently logged in user #####
################################################################################################
## Set a variable that takes the output of the current console owner and cut the result down
user=ls -l /dev/console | cut -d " " -f 4
## Run the background software check as the user.
cd /System/Library/CoreServices/Software Update.app/Contents/Resources/
sudo -u $user ./SoftwareUpdateCheck
exit 0