#!/usr/bin/ksh
#####################################################################
# TITRE:	ORAShowProc
#--------------------------------------------------------------------
# CREE LE:	12/11/94		Par: Johann CURE HP
#--------------------------------------------------------------------
# OBJET:	Montrer les process qui tournent et ne tournent pas
#		pour une instance specifiee.
#			
#====================================================================
# Modifie le:	JJ/MM/AA		Par: 
#	Motif: motif ayant justifie la modification et points
#	modifies si besoin
#               17/12/96                V. Garreau
#		ajout $Instance au nom du fichier tempo fic_temp
#		sinon file not found ...
#####################################################################
# REMARQUES: Les entetes des fonctions ont ete allegees pour plus
#            de lisibilite (fonction de petite taille et presque
#            identiques
#
#####################################################################
# CONVENTION DES CODES DE RETOUR (autre aue 0 (Ok) et 1 (erreur)
#
#====================================================================
# ACCES ET DROITS D'APPEL
#	Mode: 0777	Owner: 			Group:
#====================================================================
# PRE-REQUIS EN ENTREE
# Environnement materiel:
#	Machine: 			Constructeur: HP,SUN,IBM,SGI
# Environnement logiciel:
#	OS: hp-ux			Version: 9.05
#	    hp-ux				 10.20
#	    Solaris				 5.3
#	    Solaris				 5.5
#	    SunOs 				 4.1.3
#	    AIX					 3.x
#	    AIX					 4.2
#	    IRIX				 5.3
# Initialisation des variables globales (environnement, reseau...):
#	VARIABLE1	=	
#	VARIABLE2	=
#####################################################################
#####################################################################
# INVENTAIRE DES APPELS EXTERNES
# Script(s) appelant(s) ce script: 
#	Operation Center
#--------------------------------------------------------------------
# Script(s) appele(s) par ce script:
#	Non Applicable	
#--------------------------------------------------------------------
# Fonction(s) appelee(s) par ce script:
# - Systeme:
#	Non Applicable	
# - Internes:
#	Non Applicable
#====================================================================
# Environnement et variables globales
# importes non modifies:
#	Non Applicable
#--------------------------------------------------------------------
# Importes modifies:
#	Non Applicable
#--------------------------------------------------------------------
# Exportes:
#	NOM_VARIABLE= Non Applicable
#####################################################################
# Fonctions internes au script
#	DeterminationOS 
#	FonctionHPUX
#	FonctionSunOS
#	FonctionSolaris
#	FonctionAIX
#####################################################################

# Recuperation du nom de l'instance
typeset NomInstance=$1

# Definition des PATH :
fic_temp=/tmp/ps_OpC_ora_${NomInstance}
 
# Definition des variables globales locales script:
typeset CommandeLs			  # Commande ls en fonction de l'OS
typeset CommandePs			  # Commande ps en focntion de l'OS
typeset TypeMachine                       # Recuperation de l'OS  	
typeset VersionOS                         # Recuperation de la version de l'OS 
typeset ReferenceFonction		  # Commande differente suivant l'OS

#####################################################################
# FONCTION: 	DeterminationOS	
# CREEE LE:	12/12/94		Par: Johann CURE HP
# OBJET:	Cette fonction permet de connaitre l'OS sur lequel
#		le script se deroule
#====================================================================
# Modifiee le:	12/12/96		Par:  Vincent Garreau HP
#	Motif: prise en compte de nouvelles plate-formes HP, AIX, SOLARIS, IRIX
#####################################################################
# Modifiee le:	JJ/MM/AA		Par: 
#	Motif: motif ayant justifie la modification et points
#	modifies si besoin
#####################################################################
# REMARQUES:
# 
#####################################################################
# CONVENTION DES CODES RETOUR (autres que 0 (Ok) et 2 (Erreur))
#
#====================================================================
# Fonctions DU SCRIPT appelees
#
#####################################################################
function DeterminationOS
{
	TypeMachine=$(uname -s)           # Recuperation de l'OS  	
	VersionOS=$(uname -rv)            # Recuperation de la version de l'OS 

	case ${TypeMachine} in
	HP-UX)
		if [[ "$(echo $VersionOS|cut -d. -f2)" = "10" || "$(echo $VersionOS|cut -d. -f2)" = "11" ]]
			then ReferenceFonction=FonctionHPUX10
			else ReferenceFonction=FonctionHPUX
		fi
		CommandeLs="ls -g"
		CommandePs="ps -edf"
		;;
	SunOS)
		if [ "$(echo $VersionOS|cut -c1,2)" = "5." ] ; then
				TypeMachine="Solaris"
				ReferenceFonction=FonctionSolaris
				CommandeLs="ls -g"
				CommandePs="ps -edf"
		else	
				ReferenceFonction=FonctionSunOS
				CommandeLs="ls -l"
				CommandePs="ps -axlww"
		fi
		;;
	AIX)
		if [ "$(echo $VersionOS|cut -c 3,3)" = "4" ] 
			then ReferenceFonction=FonctionAIX42
			else ReferenceFonction=FonctionAIX
		fi
		CommandePs="ps -aef"
		;;
	IRIX)
		ReferenceFonction=FonctionIRIX
		CommandeLs="ls -g"
		CommandePs="ps -edf"
		;;

	*)	
		print "$TypeMachine non supporte par ce programme"
		exit 2
		;;
	esac
	return 0
}

#####################################################################
# FONCTION:     FonctionHP-UX
#		FonctionHPUX10
#		FonctionSunOS 
#		FonctionSolaris
#		FonctionAIX
#		FonctionAIX42
#		FonctionIRIX
# CREEE LE:     12/12/94                Par: Johann CURE HP
# OBJET:        Ces 6 fonctions execute les instructions propres a
#		chaque systeme pour obtenir les memes resultats 
#====================================================================
# Modifiee le:  JJ/MM/AA                Par:
#       Motif: motif ayant justifie la modification et points
#       modifies si besoin
#####################################################################
# REMARQUES:	Le scrip affiche le nom de l'instance et verifie
#		si les 4 process associes tournent ou ne tournent pas
#		en verifiant leur presence dans le fichier temporaire
#		ps_tmp_OpC_Oracle.
#
#####################################################################
# CONVENTION DES CODES RETOUR (autres que 0 (Ok) et 2 (Erreur))
#
#====================================================================
# Fonctions DU SCRIPT appelees
#
#####################################################################


function FonctionHPUX
	{
	typeset _ProcessOra
	print Instance = $NomInstance
	for i in ora_lgwr_${NomInstance} ora_pmon_${NomInstance} ora_smon_${NomInstance} ora_dbwr_${NomInstance} 
		do
		_ProcessOra=$(cat ${fic_temp} | grep $i)
		if [ "$_ProcessOra" != "" ]
			then print "$i actif"
		else
			print "$i non actif"
		fi
	done
	return 0
	}

function FonctionHPUX10
	{
	FonctionHPUX
	return 0
	}

function FonctionSunOS
	{
	typeset _ProcessOra
	print Instance = $NomInstance
	for i in ora_lgwr_${NomInstance} ora_pmon_${NomInstance} ora_smon_${NomInstance} ora_dbwr_${NomInstance} 
		do
		_ProcessOra=$(cat ${fic_temp} | grep $i)
		if [ "$_ProcessOra" != "" ]
			then print "$i actif"
		else
			print "$i non actif"
		fi
	done
	return 0
	}

function FonctionSolaris
	{
	typeset _ProcessOra
	print Instance = $NomInstance
	for i in ora_lgwr_${NomInstance} ora_pmon_${NomInstance} ora_smon_${NomInstance} ora_dbwr_${NomInstance} 
		do
		_ProcessOra=$(cat ${fic_temp} | grep $i)
		if [ "$_ProcessOra" != "" ]
			then print "$i actif"
		else
			print "$i non actif"
		fi
	done
	return 0
	}

function FonctionAIX
	{
	typeset _ProcessOra
	print Instance = $NomInstance
	for i in ora_lgwr_${NomInstance} ora_pmon_${NomInstance} ora_smon_${NomInstance} ora_dbwr_${NomInstance} 
		do
		_ProcessOra=$(cat ${fic_temp} | grep $i)
		if [ "$_ProcessOra" != "" ]
			then print "$i actif"
		else
			print "$i non actif"
		fi
	done
	return 0
	}

function FonctionAIX42
        {
	FonctionAIX
	return 0
	}
 
function FonctionIRIX
	{
	typeset _ProcessOra
	print Instance = $NomInstance
	for i in ora_lgwr_${NomInstance} ora_pmon_${NomInstance} ora_smon_${NomInstance} ora_dbwr_${NomInstance} 
		do
		_ProcessOra=$(cat ${fic_temp} | grep $i)
		if [ "$_ProcessOra" != "" ]
			then print "$i actif"
		else
			print "$i non actif"
		fi
	done
	return 0
	}

####################################################################
#			PROGRAMME PRINCIPAL
####################################################################

DeterminationOS

${ReferenceFonction}

if [ $? -ne 0 ]
	then
	echo "Probleme sur le programme ORAShowProc." 1>&2
	exit 1
fi
	 
exit  0
