<HTML>
<HEAD>
<TITLE>Re: [Casper] Grep(?) or other method for a logged on user.</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Thanks all for the suggestions everyone.<BR>
<BR>
Much appreciated! &nbsp;I should be good to go.<BR>
<BR>
<BR>
On 5/8/09 5:47 AM, &quot;Nichols, Jared&quot; &lt;<a href="jared.nichols@ll.mit.edu">jared.nichols@ll.mit.edu</a>&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Perhaps this would be better in this case?<BR>
<BR>
## Set a variable that takes the output of the current console owner and cut the result down<BR>
user=`ls -l /dev/console | cut -d &quot; &quot; -f 4`<BR>
<BR>
I haven&#8217;t tried it, but I would think that if nobody&#8217;s logged in, /dev/console will be owned by either nobody or root.<BR>
<BR>
j<BR>
<BR>
<BR>
On 5/7/09 16:50 , &quot;Criss Myers&quot; &lt;<a href="cmyers@uclan.ac.uk">cmyers@uclan.ac.uk</a>&gt; wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hi chaps <BR>
<BR>
Sorry if this doesn't sound right but this us what I do, if have a policy that runs at night time only every 30mins which shutsdown a mac if no one is logged in<BR>
<BR>
For me it was simple, when a user logs in a login hook touchs<BR>
/Library/Login/loggedinuser. Then when they logout it removed the file<BR>
<BR>
My policy then checks if that file exists , if so is exits, if not it shutsdown.<BR>
<BR>
<BR>
To me that seemed the simplist, as I can reuse that log file for abu script, much easier that checking directories and users folders<BR>
<BR>
Criss <BR>
<BR>
On 7 May 2009, at 21:32, <a href="DHowell@austinisd.org">DHowell@austinisd.org</a> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
I found this one to work the best for me <BR>
<BR>
username=`/usr/bin/w | grep console | awk '{print $1}'` <BR>
<BR>
<BR>
than using variable like this /Users/$username/ <BR>
<BR>
<BR>
<BR>
<BR>
D. Trey Howell <BR>
<BR>
<a href="trey.howell@austinisd.org">trey.howell@austinisd.org</a> <BR>
<BR>
Desktop Engineering <BR>
<BR>
&lt;mime-attachment.jpg&gt;&lt;mime-attachment.jpg&gt;&lt;mime-attachment.jpg&gt;&lt;mime-attachment.jpg&gt; <BR>
<BR>
This email message, including all attachments, is for the sole use of the intended recipient(s) and may contain confidential student and/or employee information. &nbsp;Unauthorized use of disclosure is prohibited under the federal Family Education Rights &amp; Privacy Act (20 U.S.C. &sect;1232g, 34 CFR Part 99, 19 TAC 247.2, Gov&amp;#8217, t Code 552.023, Educ. Code 21.355, 29 CFR 1630.14(b)(c)). &nbsp;If you are not the intended recipient, you may not use, disclose, copy or disseminate this information. &nbsp;Please call the sender immediately or reply by email and destroy all copies of the original message, including attachments. <BR>
<BR>
&nbsp;<BR>
<BR>
<BR>
<BR>
</SPAN><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><B>&quot;Thomas Larkin&quot; &lt;<a href="tlarki@kckps.org">tlarki@kckps.org</a></B></SPAN></FONT><B><SPAN STYLE='font-size:11pt'>&gt;</SPAN></B><SPAN STYLE='font-size:11pt'> <BR>
</SPAN><FONT SIZE="2"><SPAN STYLE='font-size:10pt'> <BR>
Sent by: <a href="casper-bounces@list.jamfsoftware.com">casper-bounces@list.jamfsoftware.com</a></SPAN></FONT><SPAN STYLE='font-size:11pt'> &lt;<a href="mailto:casper-bounces@list.jamfsoftware.com">mailto:casper-bounces@list.jamfsoftware.com</a>&gt; </SPAN><FONT SIZE="2"><SPAN STYLE='font-size:10pt'>05/07/09 02:03 PM</SPAN></FONT><SPAN STYLE='font-size:11pt'> 
</SPAN></FONT>
<P ALIGN=RIGHT>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><FONT SIZE="2"><SPAN STYLE='font-size:10pt'>To 
</SPAN></FONT></FONT>
<P>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><FONT SIZE="2"><SPAN STYLE='font-size:10pt'>&quot;<a href="casper@list.jamfsoftware.com">casper@list.jamfsoftware.com</a></SPAN></FONT><SPAN STYLE='font-size:11pt'>&quot; &lt;<a href="casper@list.jamfsoftware.com">casper@list.jamfsoftware.com</a>&gt;, &quot;Matt Oclassen&quot; &lt;<a href="moclassen@salesforce.com">moclassen@salesforce.com</a>&gt; 
</SPAN></FONT>
<P ALIGN=RIGHT>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><FONT SIZE="2"><SPAN STYLE='font-size:10pt'>cc<BR>
Subject 
</SPAN></FONT></FONT>
<P>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><FONT SIZE="2"><SPAN STYLE='font-size:10pt'>Re: [Casper] Grep(?) or other method for a logged on user.</SPAN></FONT><SPAN STYLE='font-size:11pt'> <BR>
<BR>
<BR>
<BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>Are these accounts local or part of a directory?</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>This could be easily done a few different ways. &nbsp;&nbsp;First and foremost I suggest anyone who manages Macs to keep their local admin accounts hidden, in like /private/var for example. &nbsp;That way it keeps them out of the /Users directory. &nbsp;Then all of your policies in place for your managed users can loop through the /users directory. &nbsp;Since the admin accounts won't be there you won't loop them out at all.</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>I kind of just came up with a quick way to do this, probably not that efficient and someone who is a better script writer may want to try it.</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>#!/bin/bash</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>#get current user logged in</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>current_user=finger -lp | grep Directory | cut -c 19-40</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>#now loop through users</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>for i in `ls /Users`</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>do</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>if [[ $i == $current_user ]]</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>then jamf policy -trigger MyPolicy</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>else echo &quot;not in /Users&quot;</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>fi</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>exit</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT><FONT FACE="Lucida Grande">done</FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <BR>
</FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT><FONT SIZE="4"><FONT FACE="Lucida Grande"><SPAN STYLE='font-size:14pt'>This was written very quick and you may want to write it a better way. &nbsp;That is where I would start though.<BR>
</SPAN></FONT><SPAN STYLE='font-size:14pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"><BR>
<BR>
___________________________<BR>
Thomas Larkin<BR>
TIS Department<BR>
KCKPS USD500<BR>
<FONT COLOR="#0000FF"><U><a href="tlarki@kckps.org">tlarki@kckps.org</a></U></FONT></FONT></SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'> &lt;<a href="mailto:tlarki@kckps.org">mailto:tlarki@kckps.org</a>&gt; <BR>
</SPAN><FONT SIZE="4"><SPAN STYLE='font-size:14pt'>blackberry: &nbsp;913-449-7589<BR>
office: &nbsp;913-627-0351<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
&gt;&gt;&gt; Matt Oclassen &lt;<a href="moclassen@salesforce.com">moclassen@salesforce.com</a></SPAN></FONT><SPAN STYLE='font-size:11pt'>&gt; 05/07/09 1:32 PM &gt;&gt;&gt; <BR>
Hello,<BR>
<BR>
I was looking for a command that I could use to verify that a user is logged onto their machine before a policy is run (as opposed to a machine being on, but sitting at the login screen)<BR>
<BR>
I want to make sure that they are logged in so they are sure to get the messaging that this policy has run.<BR>
<BR>
I am imagining something like the following:<BR>
<BR>
If any user is logged in (except for our 2 admin accounts whose name I can specify)<BR>
<BR>
Execute &nbsp;jamf policy &#8211;trigger &#8220;custom trigger&#8221;<BR>
<BR>
Else quit.<BR>
<BR>
Does anyone have an idea on the scripting for this?<BR>
<BR>
Thanks very much,<BR>
Matt Oclassen<BR>
<BR>
Desktop Systems Specialist <BR>
</SPAN><FONT SIZE="6"><SPAN STYLE='font-size:24pt'>sales <BR>
<FONT COLOR="#FF0000">force</FONT><FONT COLOR="#000080">.</FONT><FONT COLOR="#808080">com</FONT></SPAN></FONT><SPAN STYLE='font-size:11pt'> <BR>
<BR>
<BR>
</SPAN></FONT><SPAN STYLE='font-size:11pt'><FONT FACE="Consolas, Courier New, Courier">_______________________________________________<BR>
Casper mailing list<BR>
<a href="Casper@list.jamfsoftware.com">Casper@list.jamfsoftware.com</a> &lt;<a href="mailto:Casper@list.jamfsoftware.com">mailto:Casper@list.jamfsoftware.com</a>&gt; <BR>
<a href="http://list.jamfsoftware.com/mailman/listinfo/casper">http://list.jamfsoftware.com/mailman/listinfo/casper</a><BR>
</FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"> &lt;<a href="http://list.jamfsoftware.com/mailman/listinfo/casper">http://list.jamfsoftware.com/mailman/listinfo/casper</a>&gt; <BR>
</FONT></SPAN><BLOCKQUOTE><SPAN STYLE='font-size:11pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial">_______________________________________________<BR>
Casper mailing list<BR>
<a href="Casper@list.jamfsoftware.com">Casper@list.jamfsoftware.com</a><BR>
<a href="http://list.jamfsoftware.com/mailman/listinfo/casper">http://list.jamfsoftware.com/mailman/listinfo/casper</a><BR>
</FONT></SPAN></BLOCKQUOTE><SPAN STYLE='font-size:11pt'><FONT FACE="Calibri, Verdana, Helvetica, Arial"><BR>
<BR>
---<BR>
Jared F. Nichols<BR>
Desktop Engineer, Infrastructure and Operations<BR>
Information Services Department<BR>
MIT Lincoln Laboratory<BR>
244 Wood Street<BR>
Lexington, Massachusetts 02420<BR>
781.981.5436 <BR>
<BR>
<BR>
</FONT></SPAN></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE>
</BODY>
</HTML>