![]() |
Quote:
That's so easy that it borders on cheating. :D |
Quote:
Code:
ioreg -w0 -Sn Root | grep 'kCGSSessionOnConsoleKey"=Yes' | perl -pe 's/kCGSSessionOnConsoleKey"=Yes/\nkCGSSessionOnConsoleKey"=Yes/g' | grep 'kCGSSessionOnConsoleKey"=Yes' | perl -pe 's/kCGSessionLongUserNameKey"="/\n/g' | tail -n 1 | perl -pe 's/"/\n/g' | head -n 1 |
Yes but I'm always careful when data comes on a long line because sometimes order is not guaranteed. With my script order doesn't matter at all.
|
Quote:
|
Example of what I mean:
assume that sometimes kCGSessionLongUserNameKey=... comes before kCGSSessionOnConsoleKey=... your script would then fail. I'm not saying it does but as I can only check on one machine and with it's installed os I can't be sure. Is it perhaps sorted in username order or what? I just prefer to do a real parse if possible unless I have "proof" e.g. a man page that states the order. |
And if we're talking perl then use it the whole way.
Code:
ioreg -w0 -Sn Root |perl -ne '/.*{(.*?kCGSSessionOnConsoleKey"=Yes.*?)}.*/ && $1=~/"kCGSessionLongUserNameKey"="(.*?)"/ && print $1' |
An alternative is to use the 'scutil' command, asking it to show the data for the key "State:/Users/ConsoleUser".
Here's a Perl script that does this (it shows the short username): Code:
#!/usr/bin/perl |
Quote:
Quote:
|
Quote:
Code:
% time ioreg -w0 -Sn Root |perl -ne '/.*{(.*?kCGSSessionOnConsoleKey"=Yes.*?)}.*/ && $1=~/"kCGSessionLongUserNameKey"="(.*?)"/ && print $1' |
Nice one hayne. Do you have any good place to read up on scutil? The man page is rather short.
And on which os doesn't stat work? On tiger it's ok for me at least. |
Quote:
crw------- so only the owner has read permission. And so I thought that 'stat' would fail for anyone other than owner. But I realize now that the relevant permissions are those of the enclosing folder - so all is well. I don't have any better reference on 'scutil' - I agree that the man page is inadequate. Best to just run it interactively and try things: especially 'list' and 'help' |
:D Ahh even you can be mistaken.;)
|
| All times are GMT -5. The time now is 05:46 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.