Skip to main content
Solved

help with console user please


Forum|alt.badge.img+21

hi guys

Was wondering if you can help me.

For my scripts i usually use below for the currently logged in user

ls -l /dev/console | cut -d " " -f4

this returns tkimpton@rufusleonard.hq

Im trying to work out how to strip out @rufusleonard.hq so i am left with tkimpton.

Any ideas?

Best answer by mm2270

Do you get a better result with the following?-

/usr/bin/who | awk '/console/{ print $1 }'

If not, you can use your command and send it through another cut like this-

| cut -d@ -f1

That should leave you with everything from before the @ symbol, meaning "tkimpton'

View original
Did this topic help you find an answer to your question?

7 replies

mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • October 31, 2012

Do you get a better result with the following?-

/usr/bin/who | awk '/console/{ print $1 }'

If not, you can use your command and send it through another cut like this-

| cut -d@ -f1

That should leave you with everything from before the @ symbol, meaning "tkimpton'


Forum|alt.badge.img+21
  • Author
  • Honored Contributor
  • 970 replies
  • October 31, 2012

OMG wow that if friggin awesome.

Thank you very much

went on a bender last night and my brain has b een hitting a brick wall ;)


Forum|alt.badge.img+12
  • Contributor
  • 417 replies
  • October 31, 2012

following in the "1001 ways to do" X tradition: ```
who | grep console | awk '{print $1}'
```


Forum|alt.badge.img+18
  • Valued Contributor
  • 1007 replies
  • October 31, 2012

/dev/console does seem to be a bit more reliable, sometimes when logging out one user and logging in a new one who on the console can produce less than consistent results in my experience anyway...


Forum|alt.badge.img+10
  • New Contributor
  • 343 replies
  • October 31, 2012

Yet another way which avoids grep and awk:

stat -f "%Su" /dev/console


Forum|alt.badge.img+21
  • Author
  • Honored Contributor
  • 970 replies
  • November 1, 2012

Thanks guys :)


Forum|alt.badge.img+24
  • Valued Contributor
  • 1892 replies
  • November 1, 2012

You can also read the lastUser key from com.apple.loginwindow.plist


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings