#!/bin/bash

. ./param_bash.ini

FTP_TEMPL=$1
IKIT_FTP_DIR=$2
MAIL=$3
check_status()
{
    dir_num=`cat $FTP_TEMPL | wc -l`
    j=0
    count=0
    for i in `cat $FTP_TEMPL`
    do
        ${PS} | grep wget | grep -v grep >& /dev/null
        if [ "$?" != "0" ] ; then
            bash -f exl_ftp_check.bash "$FTP_USER" "$i" "$FTP_SERVER" "$temp" "$IKIT_FTP_DIR" "$FTP_PASSWD" 
            if [ "$?" != 0 ] ; then
                touch $IKIT_DIR/ROSETTA_DB_SOFT_FTP_FAILED               
                echo "The Rosetta installation automated message." | $MAIL_UTIL -s "Rosetta installation - the Rosetta Oracle DB software FTP is failed." $MAIL
                exit 1
            fi
	    let j=j+1
	    if [ "$j" == "$dir_num" ] ; then
	    	touch $IKIT_DIR/ROSETTA_DB_SOFT_FTP_COMPLETED
		echo "The Rosetta installation automated message." | $MAIL_UTIL -s "Rosetta  installation - the Rosetta Oracle DB software FTP is completed." $MAIL
		exit 0
	    fi
    	fi
    	let count=count+1
    done
}
isActive=0
${PS} | grep wget | grep -v grep >& /dev/null
isActive="$?"
while [ "${isActive}" == "0" ]
do
    sleep 30
    ${PS} | grep wget | grep -v grep >& /dev/null
    isActive="$?"
done
check_status
