#!/usr/bin/ksh
#####################################################################
# TITRE:	NOra7342Flog
#--------------------------------------------------------------------
# CREE LE:	11/12/1998		Par: S. GISLAIN
#--------------------------------------------------------------------
# OBJET:	Action automatique a partir du fichier
#		/<HostLogique>/logiciel/oracle/oracle_<NomInstance>/alert_<NomInstance>.log
#			
#====================================================================
# Modifie le:	JJ/MM/AA		Par: 
#	Motif: motif ayant justifie la modification et points
#	modifies si besoin
#####################################################################
# 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
#	FonctionHPUX10
#	FonctionSunOS
#	FonctionSolaris
#	FonctionAIX
#	FonctionAIX42
#	FonctionIRIX
#####################################################################
# Recuperation du nom de l'instance
typeset NomInstance=$1

# Recuperation du nom de host logique
typeset HostLogique=$2

# Definition des PATH :
FICHIER_LOG=/${HostLogique}/logiciel/oracle/oracle_${NomInstance}/alert_${NomInstance}.log

# Definition des variables globales locales script:
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
		;;
	SunOS)
		if [ "$(echo $VersionOS|cut -c1,2)" = "5." ] ; then
				TypeMachine="Solaris"
				ReferenceFonction=FonctionSolaris
		else	
				ReferenceFonction=FonctionSunOS
		fi
		;;
	AIX)
		if [ "$(echo $VersionOS|cut -c 3,3)" = "4" ] 
			then ReferenceFonction=FonctionAIX42
			else ReferenceFonction=FonctionAIX
		fi
		;;
	IRIX)
		ReferenceFonction=FonctionIRIX
		;;

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

#####################################################################
# 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: 	Recuperation des 30 dernieres lignes de la log
#		corespondant a une instance donnee en parametre
#
#####################################################################
# CONVENTION DES CODES RETOUR (autres que 0 (Ok) et 2 (Erreur))
#
#====================================================================
# Fonctions DU SCRIPT appelees
#
#####################################################################
function FonctionHPUX
	{
	if [[ -f ${FICHIER_LOG} ]]
	then
		tail -n 30 ${FICHIER_LOG}
	else
		print "Fichier ${FICHIER_LOG} absent !"
	fi

	return $?
	}

function FonctionHPUX10
	{
	FonctionHPUX
	return $?
	}

function FonctionSunOS
	{
	FonctionHPUX
	return $?
	}

function FonctionSolaris
	{
	FonctionHPUX
	return $?
	}

function FonctionAIX
	{
	FonctionHPUX
	return $?
	}

function FonctionAIX42
	{
	FonctionAIX
	return $?
	}

function FonctionIRIX
        {
	FonctionHPUX
	return $?
        }


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

DeterminationOS

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

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