[HELP] Monitor Guest Account

Discussion in 'macOS' started by miguelcoma, Jan 13, 2013.

  1. miguelcoma macrumors newbie

    Feb 18, 2012
    Hi! I just bought my first mac and I'd like to know if it's possible to monitor a guest account.
    I mean, I'll have a guest account and I'd like to know when someone logs in it (and optionally what he does while he is in it).

  2. switon macrumors 6502a

    Sep 10, 2012
    RE: logs versus bash...

    Hi miguelcoma,

    There are numerous solutions, depending upon what you need and how you want to be notified, and how willing you are to "get dirty" with bash coding I suppose.

    For instance, the system log file contains lines that have "loginwindow" in them, and these lines list whoever successfully logs into your machine. So in the Console.app window if you search for "loginwindow" you will see a list of the users's logins. There are also various tools for watching events happening in the logs. I'm sure there are ones for the Mac OS X, but I haven't looked into them because I use a couple of Linux ones that I build under the Mac OS X. For a simpler one, you might look into "logwatch" that can be build using the MacPorts system.

    But let's say that you just want to be notified when some user logs into your computer. Then you might write a simple bash script to check if that user is logged in and notify you if he/she is. If you then run this script repeated (possible through a number of mechanisms, all the way from "cron" through "Automator.app"), say once a minute, then you will be notified if the user logs in on a minute by minute basis. For example, the following line of bash:

    if who | grep -i guest; then echo "guest"; else echo "no guest"; fi
    checks if the user "Guest" is logged into your computer, and, if so, prints "guest" to your terminal. If "Guest" is not logged in, then "no guest" is printed to the terminal. This is just a template bash command line, as you would change the "echo "guest"" and "echo "no guest"" lines to run other shell scripts to do anything you might want done, such as notifying you through the Notification Center. In fact, the "terminal-notifier.app" is perfect for this job. If you replace the "echo "guest"" in the above code with the appropriate "terminal-notifier -message "Guest login"", then you will receive a Notification telling you of the "Guest login" whenever Guest logs into your computer. This sounds like a winner to me...

    Good luck,

    P.S. The bash code line is an IF statement that runs the "who" command to get the list of users logged into your computer. This list is piped ("|"), or sent, to the "grep -i" command that checks if the user "guest" is currently logged in. If so, then the IF is satisfied and the THEN part of the IF is executed, that is, "echo "guest"" is run to print "guest" on your terminal. If the IF statement is not satisfied, i.e., Guest is not logged into your system, then the ELSE portion of the IF statement is executed, that is, the "echo "no guest"" is executed which prints "no guest" on your terminal.
  3. miguelcoma thread starter macrumors newbie

    Feb 18, 2012
    Hi Switon,
    I was actually looking for an OSX feature or an app to do this for me, but if I can't find no other way, I will probably just learn code basics and use your suggestion.
    Thank you for your response, it was really helpful! :)
  4. switon macrumors 6502a

    Sep 10, 2012
    RE: not too much coding is required...

    Hi miguelcoma,

    As you can see from my "outline" code, not too much coding is required. I think you would find the "terminal-notifier.app" to do most of the work for you, that is, it would produce a notification in the Notification Center whenever it is triggered. I think the real problem would be not to trigger it repeatedly, and this could be accomplished by writing the output of "who" to a file, taking the md5 hash of the file and remembering it, and then checking if the md5 has changed on the new "who" output. If it has, then grep for your "Guest" and if the grep is successful, call the terminal-notifier app to generate a Notification.

    My other suggestion of "watching" the log files is also a viable option and I'm sure that there are Mac OS apps to do this, I just use the ones built from Linux and thus don't use any Mac OS ones. I'm sure someone here on the forum will be able to suggest a Mac OS app that watches the log files and reports back.

  5. miguelcoma thread starter macrumors newbie

    Feb 18, 2012
    Hi Swinton,

    thanks again, I'm going to try using the terminal notifier. I'll be here next week with the results (iMac arrives tomorrow).


Share This Page