Posted on 10-31-2012 06:44 AM
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?
Solved! Go to Solution.
Posted on 10-31-2012 06:49 AM
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'
Posted on 10-31-2012 06:49 AM
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'
Posted on 10-31-2012 06:51 AM
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 ;)
Posted on 10-31-2012 02:39 PM
following in the "1001 ways to do" X tradition: ```
who | grep console | awk '{print $1}'
```
Posted on 10-31-2012 02:42 PM
/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...
Posted on 10-31-2012 04:48 PM
Yet another way which avoids grep and awk:
stat -f "%Su" /dev/console
Posted on 11-01-2012 02:14 AM
Thanks guys :)
Posted on 11-01-2012 05:02 AM
You can also read the lastUser key from com.apple.loginwindow.plist