#!/usr/bin/ksh
#whoconnect ()
#------------------------------------------------------------------------------#
#    Module Name:  whoconnect                                                  #
#                                                                              #
#    Purpose:      Report on the NCA Users/Report Server Oracle Apps 12.1      #
#                     Connections via IP-Address.                              #
#                                                                              #
#    Environment Variables:  FORMS_RTI_DIR  and  FORMS_TRACE_DIR               #
#                                                                              #
#    Maintenance                                                               #
#    Date          Author        Description                                   #
#    -----------   ------------  --------------------------------------------  #
#    10-Oct-2009   M.Barone      Module design/creation                        #
#------------------------------------------------------------------------------#
{
        DIRNAM=$(dirname $0)
        ORASID=$(echo $CONTEXT_NAME | cut -f1 -d'_')
        HNAME=$(uname -n)

        #----------------------------------------------------------------------#
        #  TEST:  Number ($#) of arguments passed to this function?            #
        #----------------------------------------------------------------------#
        if      [ $# = 0 ]
        then
            clear
            echo 
            echo  " #--------------------------------------------------------#"
            echo  " # whoconnect:              Oracle Apps Forms-Connections #"
            echo  " #--------------------------------------------------------#"
            echo                                                               

            clear
        else
            DATTIM=$1
            clear
        fi


#------------------------------------------------------------------------------#
#  Initialize                                                                  #
#------------------------------------------------------------------------------#

#------------------------------------------------------------------------------#
#  Form-Server                                                                 #
#------------------------------------------------------------------------------#
        cd $FORMS_TRACE_DIR

        echo "#----------------------------------------------------------------#"
        echo "# whoconnect:                      Oracle Apps Forms-Connections #"
        echo "#----------------------------------------------------------------#"

#------------------------------------------------------------------------------#
#  Linux-Server: Current/Active Forms-Sessions                                 #
#------------------------------------------------------------------------------#
        echo "#----------------------------------------------------------------#"
        echo "#  Linux-Server: Current/Active Forms-Sessions                   #"
        echo "#----------------------------------------------------------------#"
        for LPIDNO in $(cat $(ls -t Servlet_RTI* | head -1) | cut -f1 -d' ')
        do
            echo
            ps -efa | grep -v grep | grep frmweb | grep $LPIDNO
        done

echo
echo

#------------------------------------------------------------------------------#
#  Forms-Server: Current/Active Forms-Sessions                                 #
#------------------------------------------------------------------------------#
        echo "#----------------------------------------------------------------#"
        echo "#  Forms-Server: Current/Active Forms-Sessions                   #"
        echo "#----------------------------------------------------------------#"
        for IPADDR in $(cat $(ls -t Servlet_RTI* | head -1) | cut -f5 -d',')
        do
            echo
            echo "IP-Address (NSLookup) for $IPADDR"
            echo "-----------------------------------------"
            nslookup $IPADDR
            echo
            echo
        done

print
print  "Please see  /tmp/whoconnect_$$.txt"
print
}