Get current user from Casper?

Not applicable

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

11 REPLIES 11

ktrampe
New Contributor II

Would this work?

who | grep "console"

Have a great afternoon,
Kerry

tlarkin
Honored Contributor

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$

jarednichols
Honored Contributor

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

Not applicable

USER='who | grep 'console' | cut ­d' ' -f1'

Gives us the shortname of the user every time.

Thanks!

tlarkin
Honored Contributor

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

bentoms
Release Candidate Programs Tester

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

Bukira
Contributor

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

bentoms
Release Candidate Programs Tester

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

Not applicable

Corrrect.

tlarkin
Honored Contributor

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.

bentoms
Release Candidate Programs Tester

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