SPY HILL Research Spy-Hill.net


Poughkeepsie, New York [DIR] [UP]
 

Enabling rwhod on Mac OS X

 

How to get the Unix rwhod service to start at boot time on a Mac; and how to use the commands to get information from it.

Last updated: 26 September 2011
Topics
Startup
Commands
Remote monitoring

The rwhod daemon is a Unix service which monitors the status of other machines on the local network, and provides this information to the local client programs rwho and ruptime.

Mac OS X includes the rwhod daemon and the user commands, but it does not come configured so that the daemon starts at boot time. The instructions

Running rwhod at start-up

  1. Become the super-user or log in as the Administrator.

  2. In the folder /Library/StartupItems create a sub-folder called rwhod

  3. In that folder you put these two files:

    StartupParameters.plist contains:

    {
      Description     = "rwho/ruptime  system";
      Provides        = ("rwhod");
      Requires        = ("Resolver");
      OrderPreference = "None";
      Messages =
      {
        start = "Starting rwho daemon";
        stop  = "Stopping rwho daemon";
      };
    }
    

    rwhod contains:

    #!/bin/sh
    #
    # Start the rwhod at system startup time on MacOSX
    #
    # Eric Myers  - 23 July 2003
    # @(#) $Id:$
    ######################################################################
    
    . /etc/rc.common
    
    # Add 'status' option 
    
    RunService ()
    {
        case $1 in 
          start  ) StartService   ;;
          stop   ) StopService    ;;
          restart) RestartService ;;
          status ) StatusReport   ;;
          *      ) echo "$0: unknown argument: $1";;
        esac
    }
    
    StatusReport ()
    {
        PID=`ps ax | grep -v grep | awk '$5 ~ /\/rwhod$/ {print $1}'`
        if [ "$PID" != "" ]; then
           echo "rwhod (pid $PID) is running... "
           exit 0
        else
           if [ -f /var/run/rwhod.pid ]; then
              echo "rwhod is stopped but pid file exists."
    	  exit 1
           else
              echo "rwhod is stopped "
    	  exit 2
           fi
        fi
    }
    
    
    StartService ()
    {
        CheckForNetwork 
        if [ "${NETWORKUP}" = "-NO-" ]; then exit; fi
    
        if [ ! -x /usr/sbin/rwhod ]; then exit; fi
    
        ConsoleMessage "Starting rwho daemon"
        /usr/sbin/rwhod
    
        # Create pid file
        PID=`ps ax | grep -v grep | awk '$5 ~ /rwhod/ {print $1} '`
        echo $PID > /var/run/rwhod.pid
    }
    
    StopService ()
    {
        PID=`ps ax | grep -v grep | awk '$5 ~ /\/rwhod$/ {print $1}'`
        if [ "$PID" != "" ]; then
            ConsoleMessage "Stopping rwho daemon"
            kill -TERM "${PID}"
            rm -f /var/run/rwhod.pid
        else
            echo "rwhod is not running."
        fi
    }
    
    RestartService ()
    {
        StopService
        StartService
    }
    
    
    RunService "$1"
    
    ##
    

  4. Make the rwhod file executable.

  5. The rwhod daemon runs as user "daemon", and so you need to change the ownership of the directory /var/rwho so that the daemon can write data to it. The command is (as root):
    # chown daemon /var/rwho

  6. Reboot.

Using the commands

You can use the information collected by rwhod by opening a command shell (via the Terminal app or ssh'ing into the machine) and giving the following commands:
ruptime
The ruptime command produces a listing of status information about machines on the local network. It is in some sense a remote version of the Unix "uptime" command.

rwho
The rhow command lists the active users on machines on the local network. In general it omits users who have been idle for over an hour, unless you include the -a flag.

Remote monitoring

Even if you don't use the commands, by running rwhod on a machine you can monitor it on any other machine which also uses rwhod.


Last modified: 26 September 2011 Copyright © 2011 by Spy Hill Research http://spy-hill.net /help/apple/rwhod.html