Posted on 01-13-2010 12:31 AM
The answer I'm looking for might already be floating around the list
somewhere, but I haven't had any luck finding it...
Is there any way I can run a script from Casper and get the currently logged
in user? A Œwho am I' command is only returning us the macs user that Casper
uses to manage the machine. Is there a way to find the real user?
Thanks,
Bob
Posted on 01-13-2010 12:34 AM
Would this work?
who | grep "console"
Have a great afternoon,
Kerry
Posted on 01-13-2010 12:53 AM
There are many methods to do this, but the most popular one on this
mailing list seems to be this
admins-imac:~ tlarkin$ ls -l /dev/console | awk '{ print $3 }' tlarkin admins-imac:~ tlarkin$
Posted on 01-13-2010 12:57 AM
I set
user=ls -l /dev/console | cut -d " " -f 4
Then, call $user in your scripts
And that works fine for me. Like Tom said, there’s loads of ways to do it.
j
Posted on 01-13-2010 01:04 PM
USER='who | grep 'console' | cut d' ' -f1'
Gives us the shortname of the user every time.
Thanks!
Posted on 01-13-2010 01:16 PM
Also, technically Casper already does this for you, if you are doing a
log in hook.
http://jamfsoftware.com/kb/article.php?id=040 (
http://jamfsoftware.com/kb/article.php?id=040 )
$3 returns the currently logged in user
Posted on 01-14-2010 01:05 AM
I'd actually like a bit of help on this..
Is $3 populated automatically via casper?
I've had trouble calling it from scripts..
Ideally, I'd like to use is as the following crude example:
rm /$3/Library/Fonts/Lithos*
i.e. to remove or edit a file somewhere under the logged in users account, yet I this always seems to run as root if run via a policy.
Ben Toms, Tel: +44 (0) 20-3037-3819
IT Helpdesk: +44 (0) 20-3037-3883
GREYgroup, The Johnson Building, 77 Hatton Garden, London, EC1N 8JS
Posted on 01-14-2010 01:29 AM
Thats coz policys run as root sot he current user is root
you need to get the logged in user via the console as per the commands
others have given
as so
user=ls -l /dev/console | cut -d " " -f 4
this gets logged in user not the user runinng the script, i believe
ONLY login hooks use $3 as the logged in user and root root
Criss
Criss Myers
Senior Customer Support Analyst (Mac Services)
Apple Certified Technical Coordinator v10.5
LIS Business Support Team
Library 301
University of Central Lancashire
Preston PR1 2HE
Ex 5054
01772 895054
Posted on 01-14-2010 01:34 AM
Thanks Chris.
So am I correct to presume that if I run these scripts @ login they'll receive $3?
Ben Toms, Tel: +44 (0) 20-3037-3819
IT Helpdesk: +44 (0) 20-3037-3883
GREYgroup, The Johnson Building, 77 Hatton Garden, London, EC1N 8JS
Posted on 01-14-2010 05:35 AM
Corrrect.
Posted on 01-15-2010 06:50 AM
Yes, correct. The $3 gets passed only at log in. So for example if you
had a script that did this....
rm -rf /Users/$3/Library/Preferences/com.company.someplist
It would automatically get the current user logging in, this is because
log in hooks run as the root user.
Posted on 01-15-2010 06:59 AM
Thanks all..
CCA in London next week so hopefully.. I’ll hopefully be helpful afterwards ?
Ben Toms, Tel: +44 (0) 20-3037-3819
IT Helpdesk: +44 (0) 20-3037-3883
GREYgroup, The Johnson Building, 77 Hatton Garden, London, EC1N 8JS