Script to Analyze 'last' Data

ryan_panning
New Contributor

Ok, this is an offshoot of the other "Script Priority" topic I started
earlier today.

What I'd like to do is calculate what user has been logged into the
computer the longest. Not the last, most recent user. So far I have a
PHP script that processes the 'last' output and calculates the session
times, sorts it and gets the top user. From there, I do an LDAP lookup
to get the real user name, but that's already in Bash/sh. I'd have done
this all in Bash to start with but I'm more familiar with PHP.

So, to start out, I can get the data needed by calling this command. I'm
sure you understand this one, but just in case. "Last" is getting a list
of all computer/user sessions. "Grep" is getting just the
console/desktop sessions. And finally, "awk" is getting just the
columns/fields that I need.

last | grep console | awk '{print $1 " " $NF}'

6 REPLIES 6

ryan_panning
New Contributor

get the top most user. Using PHP (attached) I did this by a regex
pattern and such. I'm sure something similar could be done with Bash,
just not as familiar yet. Any input would be great. Thanks!

~ Ryan

------_=_NextPart_002_01CBD2D6.08952B09
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v"urn:schemas-microsoft-com:vml" xmlns:o"urn:schemas-microsoft-com:office:office" xmlns:w"urn:schemas-microsoft-com:office:word" xmlns:m"http://schemas.microsoft.com/office/2004/12/omml" xmlns"http://www.w3.org/TR/REC-html40"><head><meta http-equivContent-Type content"text/html; charsetus-ascii"><meta nameGenerator content"Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:11.0pt; font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink {mso-style-priority:99; color:blue; text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:purple; text-decoration:underline;}
span.EmailStyle17 {mso-style-type:personal-compose; font-family:"Calibri","sans-serif"; color:windowtext;}
.MsoChpDefault {mso-style-type:export-only; font-family:"Calibri","sans-serif";}
@page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1 {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext"edit" spidmax"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext"edit">
<o:idmap v:ext"edit" data"1" />
</o:shapelayout></xml><![endif]--></head><body langEN-US linkblue vlinkpurple><div classWordSection1><p classMsoNormal>Ok, this is an offshoot of the other &#8220;Script Priority&#8221; topic I started earlier today.<o:p></o:p></p><p classMsoNormal><o:p>&nbsp;</o:p></p><p classMsoNormal>What I&#8217;d like to do is calculate what user has been logged into the computer the longest. Not the last, most recent user. So far I have a PHP script that processes the &#8216;last&#8217; output and calculates the session times, sorts it and gets the top user. From there, I do an LDAP lookup to get the real user name, but that&#8217;s already in Bash/sh. I&#8217;d have done this all in Bash to start with but I&#8217;m more familiar with PHP.<o:p></o:p></p><p classMsoNormal><o:p>&nbsp;</o:p></p><p classMsoNormal>So, to start out, I can get the data needed by calling this command. I&#8217;m sure you understand this one, but just in case. &#8220;Last&#8221; is getting a list of all computer/user sessions. &#8220;Grep&#8221; is getting just the console/desktop sessions. And finally, &#8220;awk&#8221; is getting just the columns/fields that I need.<o:p></o:p></p><p classMsoNormal><o:p>&nbsp;</o:p></p><p classMsoNormal><span style'font-family:"Courier New"'>last | grep console | awk '{print $1 &quot; &quot; $NF}'</span><o:p></o:p></p><p classMsoNormal><o:p>&nbsp;</o:p></p><p classMsoNormal>From there, I need to add each users session time, sort the totals, and get the top most user. Using PHP (attached) I did this by a regex pattern and such. I&#8217;m sure something similar could be done with Bash, just not as familiar yet. Any input would be great. Thanks!</p><p classMsoNormal><o:p>&nbsp;</o:p></p><p classMsoNormal>~ Ryan<o:p></o:p></p></div></body></html>
------_=_NextPart_002_01CBD2D6.08952B09--

------_=_NextPart_001_01CBD2D6.08952B09
Content-Type: text/plain; name="getLongestUser.php.txt"
Content-Transfer-Encoding: base64
Content-Description: getLongestUser.php.txt
Content-Disposition: attachment; filename="getLongestUser.php.txt"

IyEvdXNyL2Jpbi9waHAKPD9waHAKCi8vIEdldCByYXcgb3V0cHV0IGZyb20gdGhlIHNoZWxsCiRz
ZXNzaW9ucyA9IHNoZWxsX2V4ZWMoJ2xhc3QgfCBncmVwIGNvbnNvbGUgfCBhd2sgXCd7cHJpbnQg
JDEgIiAiICRORn1cJycpOwoKLy8gU2VwYXJhdGUgZWFjaCBsaW5lIGludG8gc2Vzc2lvbnMKJHNl
c3Npb25zID0gZXhwbG9kZShQSFBfRU9MLCAkc2Vzc2lvbnMpOwoKLy8gUmVtb3ZlIGxhc3QgbGlu
ZSBpZiBlbXB0eQppZiAoZW5kKCRzZXNzaW9ucykgPT0gJycpIHsKICAgIGFycmF5X3BvcCgkc2Vz
c2lvbnMpOwp9CgovLyBTZXBhcmF0ZSBlYWNoIHNlc3Npb24gZnJvbSB0aGUgdXNlciBhbmQgdGlt
ZQphcnJheV93YWxrKCRzZXNzaW9ucywgY3JlYXRlX2Z1bmN0aW9uKCcmJGUsJGsnLCAnJGU9ZXhw
bG9kZSgiICIsICRlKTsnKSk7CgovLyBQbGFjZWhvbGRlciBmb3IgdXNlciA9PiBsb2dnZWQtaW4g
dGltZXMKJGxvZ2luX3RpbWVzID0gYXJyYXkoKTsKCi8vIExvb3AgdGhyb3VnaCBlYWNoIHNlc3Np
b24KZm9yZWFjaCAoJHNlc3Npb25zIGFzICRzZXNzaW9uKSB7CgogICAgLy8gTGlzdCB0aGUgc2Vz
c2lvbiBkZXRhaWxzCiAgICBsaXN0KCR1c2VyLCAkdGltZSkgPSAkc2Vzc2lvbjsKCiAgICAvLyBJ
Z25vcmUgcG9vcmx5IGZvcm1hdHRlZCB0aW1lcwogICAgLy8gRWxzZSBwYXJzZSB0aGUgdGltZSB0
byBnZXQgZCtoaDptbQogICAgaWYgKCFwcmVnX21hdGNoKCcvXCgoKFxkKylcKyk/KFxkezJ9KVw6
KFxkezJ9KVwpLycsICR0aW1lLCAkbWF0Y2hlcykpIHsKICAgICAgICBjb250aW51ZTsKICAgIH0K
CiAgICAvLyBDb252ZXJ0IHRvIG1pbnV0ZXMKICAgICR0aW1lICA9ICAoaW50KSAkbWF0Y2hlc1s0
XTsKICAgICR0aW1lICs9ICgoaW50KSAkbWF0Y2hlc1szXSAqIDYwKTsKICAgICR0aW1lICs9ICgo
aW50KSAkbWF0Y2hlc1syXSAqIDI0ICogNjApOwoKICAgIC8vIEFkZCB1c2VycyBzZXNzaW9uIHRp
bWUgdG8gdGhlIHRvdGFsIGxvZ2dlZC1pbiB0aW1lCiAgICBAJGxvZ2luX3RpbWVzWyR1c2VyXSAr
PSAkdGltZTsKfQoKLy8gU29ydCBieSBsb2dnZWQtaW4gdGltZQphcnNvcnQoJGxvZ2luX3RpbWVz
LCBTT1JUX05VTUVSSUMpOwoKLy8gR2V0IHRvcCBtb3N0IHVzZXIKJHVzZXJuYW1lID0gKHN0cmlu
Zykga2V5KCRsb2dpbl90aW1lcyk7CgovLyBXcml0ZSB1c2VybmFtZSB0byB0ZW1wb3JhcnkgZmls
ZQokZmlsZSA9IEBmb3BlbignL3ByaXZhdGUvdG1wL3VzZXJfbmFtZS50eHQnLCAndycpOwpmd3Jp
dGUoJGZpbGUsICR1c2VybmFtZSk7CmZjbG9zZSgkZmlsZSk7CgovLyBSZXR1cm4gdGhlIHJlc3Vs
dAplY2hvICJMb25nZXN0IFVzZXI6ICR1c2VybmFtZSI7Cg=

------_=_NextPart_001_01CBD2D6.08952B09--

tlarkin
Honored Contributor

Casper keeps a complete list of the last log under the usage logs. Here is a snippet

Action

Who

Date

login 14devlov Wednesday, September 01 2010 at 7:28 AM

startup

Wednesday, September 01 2010 at 7:27 AM

login 14devlov Tuesday, August 24 2010 at 7:27 AM

startup

Tuesday, August 24 2010 at 7:26 AM

login 14devlov Saturday, August 07 2010 at 12:05 PM

startup

Saturday, August 07 2010 at 12:04 PM

startup

Thursday, July 22 2010 at 9:04 AM

login hadmin Wednesday, July 21 2010 at 3:40 PM

startup

Wednesday, July 21 2010 at 3:38 PM

startup

Wednesday, July 21 2010 at 3:16 PM

login 12jascor Tuesday, May 11 2010 at 11:00 AM

startup

Tuesday, May 11 2010 at 10:59 AM

login 12jascor Tuesday, May 04 2010 at 9:23 AM

startup

Tuesday, May 04 2010 at 9:21 AM

login 12jascor Thursday, April 29 2010 at 9:26 AM

How does this differ from what you are trying to accomplish here? You
want this to basically see the difference and time a user logs in versus
another?

--missing content--

get the top most user. Using PHP (attached) I did this by a regex
pattern and such. I’m sure something similar could be done with Bash,
just not as familiar yet. Any input would be great. Thanks!

~ Ryan

This message has been sent from the Kansas City, Kansas Public Schools.
The information contained in this email and any attachments may be
privileged and confidential, and are intended only for the individual or
entity identified as the addressee. If you are not the addressee, or if
the message has been addressed to you in error, you are not authorized
to read, retain, copy, or distribute the message or any attachments. If
you have received the message in error, please delete it and any
attachments and notify the sender by return e-mail or by telephone.
Thank you.

--=Part68444C03.1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Content-Description: HTML

<html w"urn:schemas-microsoft-com:office:word" v"urn:schemas-microsof
t-com:vml" xmlns"http://www.w3.org/TR/REC-html40" o"urn:schemas-micro
soft-com:office:office" m"http://schemas.microsoft.com/office/2004/12/om
ml"> <head> <style type"text/css"> <!-- a:visited { color: purple; text-decoration: underline } span.emailstyle17 { font-family: Calibri,sans-serif; color: black } li.msonormal { font-family: Calibri,sans-serif; margin-top: 0in; margin-left: 0in; margin-right: 0in; font-size: 11.0pt; margin-bottom: .0001pt } .msochpdefault { font-family: Calibri,sans-serif } a:link { color: blue; text-decoration: underline } p.msonormal { font-family: Calibri,sans-serif; margin-top: 0in; margin-left: 0in; margin-right: 0in; font-size: 11.0pt; margin-bottom: .0001pt } span.msohyperlink { color: blue; text-decoration: underline } span.msohyperlinkfollowed { color: purple; text-decoration: underline } div.msonormal { font-family: Calibri,sans-serif; margin-top: 0in; margin-left: 0in; margin-right: 0in; font-size: 11.0pt; margin-bottom: .0001pt } --> </style>

</head> <body vlink"purple" link"blue" lang"EN-US"> <p style"margin-top: 0; margin-bottom: 0"> <font face"Lucida Grande" size"3">Casper keeps a complete list of the last log under the usage logs. &nbsp;Here is a snippet</font> </p>
<br> <table> <tr>
<br> </tr> <tr valign"top"> <td background"images/sub.gif"> <table border"0" width"100%" cellpadding"0" cellspacing
"0"> <tr> <td background"images/column_header.gif" height"15"> <table border"0" width"100%" cellpadding"0" cellspacing"0"> <tr> <td nowrap"nowrap" align"center"> <p style"margin-top: 0; margin-bottom: 0"> &#160;<font class"sub">Action</font>&#160; </p> </td> <td width"5">
<br> </td> </tr> </table> </td> </tr> </table> </td> <td background"images/sub.gif"> <table border"0" width"100%" cellpadding"0" cellspacing
"0"> <tr> <td background"images/column_header.gif" height"15"> <table border"0" width"100%" cellpadding"0" cellspacing"0"> <tr> <td width"10">
<br> </td> <td nowrap"nowrap" align"center"> <p style"margin-top: 0; margin-bottom: 0"> &#160;<font class"sub">Who</font>&#160; </p> </td> <td width"5">
<br> </td> </tr> </table> </td> </tr> </table> </td> <td background"images/sub.gif"> <table border"0" width"100%" cellpadding"0" cellspacing
"0"> <tr> <td background"images/column_header.gif" height"15"> <table border"0" width"100%" cellpadding"0" cellspacing"0"> <tr> <td width"10">
<br> </td> <td nowrap"nowrap" align"center"> <p style"margin-top: 0; margin-bottom: 0"> &#160;<font class"sub">Date</font>&#160; </p> </td> <td width"5">
<br> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr bgcolor"#ffffff"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;login&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;14devlov&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Wednesday&#44; September 01 2010 at 7:28 AM&#160; </p> </td> </tr> <tr bgcolor"#eeeeee"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;startup&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Wednesday&#44; September 01 2010 at 7:27 AM&#160; </p> </td> </tr> <tr bgcolor"#ffffff"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;login&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;14devlov&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Tuesday&#44; August 24 2010 at 7:27 AM&#160; </p> </td> </tr> <tr bgcolor"#eeeeee"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;startup&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Tuesday&#44; August 24 2010 at 7:26 AM&#160; </p> </td> </tr> <tr bgcolor"#ffffff"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;login&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;14devlov&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Saturday&#44; August 07 2010 at 12:05 PM&#160; </p> </td> </tr> <tr bgcolor"#eeeeee"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;startup&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Saturday&#44; August 07 2010 at 12:04 PM&#160; </p> </td> </tr> <tr bgcolor"#ffffff"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;startup&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Thursday&#44; July 22 2010 at 9:04 AM&#160; </p> </td> </tr> <tr bgcolor"#eeeeee"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;login&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;hadmin&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Wednesday&#44; July 21 2010 at 3:40 PM&#160; </p> </td> </tr> <tr bgcolor"#ffffff"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;startup&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Wednesday&#44; July 21 2010 at 3:38 PM&#160; </p> </td> </tr> <tr bgcolor"#eeeeee"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;startup&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Wednesday&#44; July 21 2010 at 3:16 PM&#160; </p> </td> </tr> <tr bgcolor"#ffffff"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;login&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;12jascor&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Tuesday&#44; May 11 2010 at 11:00 AM&#160; </p> </td> </tr> <tr bgcolor"#eeeeee"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;startup&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Tuesday&#44; May 11 2010 at 10:59 AM&#160; </p> </td> </tr> <tr bgcolor"#ffffff"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;login&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;12jascor&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Tuesday&#44; May 04 2010 at 9:23 AM&#160; </p> </td> </tr> <tr bgcolor"#eeeeee"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;startup&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Tuesday&#44; May 04 2010 at 9:21 AM&#160; </p> </td> </tr> <tr bgcolor"#ffffff"> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;&#32;login&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;12jascor&#160; </p> </td> <td> <p style"margin-top: 0; margin-bottom: 0"> &#160;Thursday&#44; April 29 2010 at 9:26 AM&#160; </p> </td> </tr> </table>
<br> <br> <p style"margin-top: 0; margin-bottom: 0"> <font face"Lucida Grande" size"3">How does this differ from what you are trying to accomplish here&#63; &nbsp;You want this to basically see the difference and time a user logs in versus another&#63;</f
ont><br><br>&gt;&gt;&gt; &quot;Panning&#44; Ryan&quot; &lt;Ryan.Panning at dis
trict196.org&gt; 2/22/2011 3:18 PM &gt;&gt;&gt;<br> </p> <div class"wordsection1"> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> Ok&#44; this is an offshoot of the other&#32;&#8220;Script Priority&#8221;&#32;topic I started earlier today.<o p"#DEFAULT"></o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> <o p"#DEFAULT"> &#160;</o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> What I&#8217;d like to do is calculate what user has been logged into the computer the longest. Not the last&#44; most recent user. So far I have a PHP script that processes the&#32;&#8216;last&#8217;&#32;output and calculates the session times&#44; sorts it and gets the top user. From there&#44; I do an LDAP lookup to get the real user name&#44; but that&#8217;s already in Bash/sh. I&#8217;d have done this all in Bash to start with but I&#8217;m more familiar with PHP.<o p"#DEFAULT"></o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> <o p"#DEFAULT"> &#160;</o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> So&#44; to start out&#44; I can get the data needed by calling this command. I&#8217;m sure you understand this one&#44; but just in case.&#32;&#8220;Last&#8221;&#32;is getting a list of all computer/user sessions.&#32;&#8220;Grep&#8221;&#32;is getting just the console/desktop sessions. And finally&#44;&#32;&#8220;awk&#8221;&#32;is getting just the columns/fields that I need.<o p"#DEFAULT"></o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> <o p"#DEFAULT"> &#160;</o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> <span style"font-family: Courier New"><font face"Courier New">last&#32;&#124;&#32;grep console&#32;&#124;&#32;awk &#39;&#123;print &#36;1 &quot; &quot; &#36;NF&#125;&#39;</font></span><o p"#DEFAULT"></o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> <o p"#DEFAULT"> &#160;</o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> From there&#44; I need to add each users session time&#44; sort the totals&#44; and get the top most user. Using PHP &#40;attached&#41; I did this by a regex pattern and such. I&#8217;m sure something similar could be done with Bash&#44; just not as familiar yet. Any input would be great. Thanks&#33; </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> <o p"#DEFAULT"> &#160;</o> </p> <p style"margin-top: 0; margin-bottom: 0" class"msonormal"> &#126;&#32;Ryan<o p"#DEFAULT"></o> </p> </div> <BR>

<div> This message has been sent from the Kansas City, Kansas Public Schools. The information contained in this email and any attachments may be privileged and confidential, and are intended only for the individual or entity identified as the addressee. If you are not the addressee, or if the message has been addressed to you in error, you are not authorized to read, retain, copy, or distribute the message or any attachments. If you have received the message in error, please delete it and any attachments and notify the sender by return e-mail or by telephone.

Thank you. </div> </BODY></HTML>

--=Part68444C03.1=--

ernstcs
Contributor III

Not exactly the same thing...

We actually have scripts that run at login and logout that curl data to a webpage that then places the data into a separate MySQL schema. We can then use this data for determining lab usage, unique logins and number of them. Could use it for duration if we wanted to. It's also used for another system that allows students to find available lab computers.

Not sure if a whole new system is what you're after, but it works well here. I'd share the scripts if there is interest.

Don't recall what would work for this that already exists in the JSS.

ryan_panning
New Contributor

Alright, end goal, to populate a computers Username and Real Name in Casper. We have policies setup to schedule Recon to run once per month. Right now the policies just have the Update Inventory checked in the Advanced tab. I would change this to instead run the command `jamf recon –endUsername “<<from script>>” –realname “<<from script>>”`.

In education, most computers are going to be used by several users. But the teacher computers are mostly used by, well, the teachers. But, students may login to the computer as well. In this case the student may be the “last” user but it’s really the teachers computer. That’s why a proper calculation would be better.

So my thoughts are, run a script to do the calculation. Then set the username and realname in temporary files so that the jamf recon command can `cat /private/tmp/user_name.txt`, get the username and realname from those temporary files.

~ Ryan

ryan_panning
New Contributor

That sounds like a good idea for gauging computer usage. But we're just
looking to populate the field in Casper to help with inventory searches
and have the name show up in Remote. Mainly things in Casper. Thanks for
the offer though.

~ Ryan

rmanly
Contributor III

I just broke myself of the bad habit after many years, lol...but you
should almost never need to have grep and sed or awk in same line.

last | awk '/console/{print $1 " " $NF}'

Saves you from spawning an additional subshell.

Ryan M. Manly
Glenbrook High Schools

funny link = http://partmaps.org/era/unix/award.html#grep