<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! I should be good to go.<BR>
<BR>
<BR>
On 5/8/09 5:47 AM, "Nichols, Jared" <<a href="jared.nichols@ll.mit.edu">jared.nichols@ll.mit.edu</a>> 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 " " -f 4`<BR>
<BR>
I haven’t tried it, but I would think that if nobody’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 , "Criss Myers" <<a href="cmyers@uclan.ac.uk">cmyers@uclan.ac.uk</a>> 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>
<mime-attachment.jpg><mime-attachment.jpg><mime-attachment.jpg><mime-attachment.jpg> <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. Unauthorized use of disclosure is prohibited under the federal Family Education Rights & Privacy Act (20 U.S.C. §1232g, 34 CFR Part 99, 19 TAC 247.2, Gov&#8217, t Code 552.023, Educ. Code 21.355, 29 CFR 1630.14(b)(c)). If you are not the intended recipient, you may not use, disclose, copy or disseminate this information. Please call the sender immediately or reply by email and destroy all copies of the original message, including attachments. <BR>
<BR>
<BR>
<BR>
<BR>
<BR>
</SPAN><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><B>"Thomas Larkin" <<a href="tlarki@kckps.org">tlarki@kckps.org</a></B></SPAN></FONT><B><SPAN STYLE='font-size:11pt'>></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'> <<a href="mailto:casper-bounces@list.jamfsoftware.com">mailto:casper-bounces@list.jamfsoftware.com</a>> </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'>"<a href="casper@list.jamfsoftware.com">casper@list.jamfsoftware.com</a></SPAN></FONT><SPAN STYLE='font-size:11pt'>" <<a href="casper@list.jamfsoftware.com">casper@list.jamfsoftware.com</a>>, "Matt Oclassen" <<a href="moclassen@salesforce.com">moclassen@salesforce.com</a>>
</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. First and foremost I suggest anyone who manages Macs to keep their local admin accounts hidden, in like /private/var for example. That way it keeps them out of the /Users directory. Then all of your policies in place for your managed users can loop through the /users directory. 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 "not in /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'>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. 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'> <<a href="mailto:tlarki@kckps.org">mailto:tlarki@kckps.org</a>> <BR>
</SPAN><FONT SIZE="4"><SPAN STYLE='font-size:14pt'>blackberry: 913-449-7589<BR>
office: 913-627-0351<BR>
<BR>
<BR>
<BR>
<BR>
<BR>
>>> Matt Oclassen <<a href="moclassen@salesforce.com">moclassen@salesforce.com</a></SPAN></FONT><SPAN STYLE='font-size:11pt'>> 05/07/09 1:32 PM >>> <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 jamf policy –trigger “custom trigger”<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> <<a href="mailto:Casper@list.jamfsoftware.com">mailto: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><FONT FACE="Calibri, Verdana, Helvetica, Arial"> <<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>
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>