#!/bin/ksh
#=========== Global directives ===========
# @ job_name = conso
# @ shell = /bin/ksh
# @ output = log/$(job_name).$(step_name).$(jobid)
# @ error = $(output)
## Date de demarrage calculee
#STARTDATE 
## Pour adapp
# @ requirements = (Feature == "prepost")

#=========== Step 1 directives ===========
#============== Before execution =================
# @ step_name = before_execution
## Pour adapp
# @ requirements = (Feature == "prepost")
## Type de travail
# @ job_type = serial
## Temp CPU max
# @ wall_clock_limit = 1:00:00
# @ queue

#=========== Step 2 directives ===========
#============= Execution =============
# @ step_name = execution
## Dependance
# @ dependency = (before_execution == 0)
## Pour adapp
# @ requirements = (Feature == "prepost")
## Type de travail
# @ job_type = serial
## Temp CPU max
# @ wall_clock_limit = 1:00:00
# @ queue

# #=========== Step 3 directives ===========
# #============== After execution =================
# # @ step_name = after_execution
# ## Dependance
# # @ dependency = (execution == 0)
# ## Pour adapp
# # @ requirements = (Feature == "prepost")
# ## Type de travail
# # @ job_type = serial
# ## Temp CPU max
# # @ wall_clock_limit = 1:00:00
# # @ queue

case ${LOADL_STEP_NAME} in 
  #============ Step 1 commands ============ 
  #======= Sequential preprocessing ========
  before_execution )
    set -vx
    # ${LOADL_STEP_INITDIR} == repertoire ou a ete fait le llsubmit
    cd ${LOADL_STEP_INITDIR}
    # Calcul de la date suivante : + 1 jours
    #demain=$(date "+%m/%d/%Y %H:%M" --date "+1 days")
    demain=$(date "+%m/%d/%Y 23:00" --date "+1 days")
    sed s%^#STARTDATE%"# @ startdate = ${demain}"%g job_conso > job_tmp
    # Soumission de la prochaine recolte
    llsubmit job_tmp
    rm job_tmp
  ;;

  #=========== Step 2 directives ===========
  #========== Sequential execution =========
  execution )
    set -vx
    ${LOADL_STEP_INITDIR}/bin/recolte.sh
  ;;

  # #=========== Step 3 directives ===========
  # #============ After execution ============
  # after_execution )
  #   set -vx
  #   cd ${LOADL_STEP_INITDIR}
  #   echo "Ok!" > done.txt
  # ;; 

esac 

