[1728] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | #on veut archiver les fichiers Debug. |
---|
| 4 | #Ils seront tous regroupes dans un repertoire DEBUG commun |
---|
| 5 | # on les renommes (repertoire DEBUG) de la meme maniere que les fichiers restart |
---|
| 6 | # puis on les archive via tar par periode |
---|
| 7 | #Creation des listes dans un repertoire debug_tar |
---|
| 8 | |
---|
| 9 | config_card=${1} |
---|
| 10 | LISTE_DMNFS=${2} |
---|
| 11 | |
---|
| 12 | |
---|
[1900] | 13 | export JOB_DIR=${JOB_DIR:-${TMP_MIGR_DATA}} |
---|
[1728] | 14 | export IGCM_DEM=${IGCM_DEM:-${SCRATCHDIR}/IGCM_DEM} |
---|
| 15 | export IGCM_TMP=${IGCM_TMP:-${IGCM_DEM}/tmp} |
---|
| 16 | mkdir -p ${IGCM_DEM} |
---|
| 17 | mkdir -p ${IGCM_TMP} |
---|
| 18 | clean_tmp=${clean_tmp:-yes} |
---|
| 19 | EXE_DIR=$(dirname ${0}) |
---|
| 20 | SCRIPT_NAME=$(basename ${0} ) |
---|
| 21 | |
---|
| 22 | source ${EXE_DIR}/DEM_utilities.sh |
---|
| 23 | |
---|
[1822] | 24 | # gpdebug : verif si le present script a ete execute jusqu'au bout ######### |
---|
| 25 | MonitoringInfo="${SCRIPT_NAME}-->OK" |
---|
| 26 | simuMonitoring_check "$MonitoringInfo" "$config_card" |
---|
| 27 | |
---|
[1728] | 28 | DEM_log -0 "Demarrage de ${SCRIPT_NAME}" |
---|
| 29 | |
---|
| 30 | #### 0- lecture de config.card |
---|
| 31 | #### on veut les renseignements suivants : |
---|
| 32 | #### JobName, PATH_SIMUL, DateBegin et DateEnd |
---|
| 33 | eval $(grep JobName ${config_card}) |
---|
| 34 | eval $(grep PATH_SIMUL_FULL ${config_card}) |
---|
| 35 | eval $(grep DateBegin ${config_card}) |
---|
| 36 | eval $(grep DateEnd ${config_card}) |
---|
| 37 | eval $(grep IGCM_DEM_SIMU ${config_card}) |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | #### Preparation de l'environnement |
---|
| 41 | # repertoire dans lequel seront renommes les fichiers de debug |
---|
| 42 | STORE_DEBUG=$IGCM_DEM_SIMU/DEBUG |
---|
| 43 | mkdir -p ${STORE_DEBUG} |
---|
| 44 | |
---|
| 45 | # repertoire dans lequel nous stockerons les listes de debug a archiver |
---|
| 46 | DEBUG_TAR=$IGCM_DEM_SIMU/debug_tar |
---|
| 47 | mkdir -p ${DEBUG_TAR} |
---|
[1730] | 48 | STORE_CP=$IGCM_DEM_SIMU/store_cp |
---|
| 49 | mkdir -p ${STORE_CP} |
---|
[1728] | 50 | |
---|
| 51 | # lecture de periodpack dans ${IGCM_DEM_SIMU}/period_pack.txt |
---|
| 52 | period_pack=`awk '{print $0} ' ${IGCM_DEM_SIMU}/period_pack.txt` |
---|
| 53 | |
---|
| 54 | #### 1- renommer les fichiers ###### |
---|
| 55 | DEM_log -1 "Renommer les fichiers de Debug" |
---|
| 56 | |
---|
| 57 | cd ${STORE_DEBUG} |
---|
[1911] | 58 | if [ "x${STORE_DEBUG}" != "x" ] |
---|
| 59 | then |
---|
[1728] | 60 | rm -rf * |
---|
[1911] | 61 | fi |
---|
[1763] | 62 | # On copie les fichiers de Debug sur le scratchdir en changeant le nom et conservant la date |
---|
[1925] | 63 | grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep Debug | grep "f "| awk '{print $3}' | sed '/^.*Debug$/d' | sort >> ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
[1924] | 64 | |
---|
[1878] | 65 | # Test si il y a un repertoire Debug |
---|
| 66 | listDebugNbLines=`cat ${IGCM_TMP}/${$}.liste_debug_files.txt | wc -l ` |
---|
| 67 | if [ "x${listDebugNbLines}" == "x0" ] |
---|
| 68 | then |
---|
| 69 | DEM_log -0 "Pas de repertoire Debug pour cette simulation" |
---|
| 70 | else |
---|
[1763] | 71 | # cas particulier : les fichiers Bands sont conserves sans etre archives |
---|
[1878] | 72 | grep ${JobName}_Bands ${IGCM_TMP}/${$}.liste_debug_files.txt >> ${STORE_CP}/cp_files.list |
---|
| 73 | sed "/${JobName}_Bands/d" ${IGCM_TMP}/${$}.liste_debug_files.txt > ${IGCM_TMP}/${$}.liste_debug_files.txt_tmp |
---|
| 74 | mv ${IGCM_TMP}/${$}.liste_debug_files.txt_tmp ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
[1924] | 75 | |
---|
| 76 | # on s assure que les fichiers restant sont bien des fichiers dans Debug et pas des fichiers dans des sous-repertoires" |
---|
| 77 | for file in `cat ${IGCM_TMP}/${$}.liste_debug_files.txt ` ; do |
---|
| 78 | dir=$( echo $file | sed -e "s%.*Debug/%%") |
---|
| 79 | testdir=$(dirname ${dir}) |
---|
| 80 | if [ $testdir != "." ]; then |
---|
| 81 | echo $( grep ${file} ${IGCM_TMP}/${$}.liste_debug_files.txt) >> ${IGCM_TMP}/${$}.liste_no_debug_files.txt |
---|
| 82 | fi |
---|
| 83 | done |
---|
| 84 | if [ -f ${IGCM_TMP}/${$}.liste_no_debug_files.txt ]; then |
---|
| 85 | join -t % -v 1 ${IGCM_TMP}/${$}.liste_debug_files.txt ${IGCM_TMP}/${$}.liste_no_debug_files.txt > ${IGCM_TMP}/${$}.info_tmp.txt |
---|
| 86 | mv ${IGCM_TMP}/${$}.info_tmp.txt ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
| 87 | rm -f ${IGCM_TMP}/${$}.liste_no_debug_files.txt |
---|
| 88 | fi |
---|
[1878] | 89 | gawk -F/ '{dest_name=$(NF-2)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
[1763] | 90 | #on fait de meme avec les fichiers out_gcm.e stockes dans le repertoire Out/ qui seront prefixes par Out_ |
---|
[1878] | 91 | rm -f ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
[1913] | 92 | grep ${PATH_SIMUL_FULL}/ ${LISTE_DMNFS} | grep -w Out | awk '{print $3}' | sed '/^.*Out$/d' > ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
[1878] | 93 | gawk -F/ '{dest_name=$(NF-1)("_") $(NF); system("ln -s " $0 " "dest_name)}' ${IGCM_TMP}/${$}.liste_debug_files.txt |
---|
[1763] | 94 | |
---|
| 95 | |
---|
[1878] | 96 | ls -l ${STORE_DEBUG} > ${IGCM_TMP}/${$}.new_liste_debug_files.txt |
---|
[2045] | 97 | |
---|
| 98 | |
---|
| 99 | #creation des listes en fonction des suffixes |
---|
| 100 | if [ "x${ON_IDRIS}" == "xno" ] |
---|
| 101 | then |
---|
| 102 | awk '{if (NR >1) print $9}' ${IGCM_TMP}/${$}.new_liste_debug_files.txt > ${IGCM_TMP}/${$}.new_liste_debug_files.txt_tmp |
---|
| 103 | else |
---|
| 104 | awk '{if (NR >1) print $8}' ${IGCM_TMP}/${$}.new_liste_debug_files.txt > ${IGCM_TMP}/${$}.new_liste_debug_files.txt_tmp |
---|
| 105 | fi |
---|
| 106 | sort ${IGCM_TMP}/${$}.new_liste_debug_files.txt_tmp > ${IGCM_TMP}/${$}.order_new_liste_debug_files.txt |
---|
| 107 | ref=`awk -F_ '{if (NR==1) print $1}' ${IGCM_TMP}/${$}.order_new_liste_debug_files.txt` |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | i=1 |
---|
| 112 | for new_file in `awk '{print $0}' ${IGCM_TMP}/${$}.order_new_liste_debug_files.txt`; do |
---|
| 113 | new_ref=$( echo ${new_file} | sed -e "s/_.*//") |
---|
| 114 | |
---|
| 115 | if [ ${new_ref} == ${ref} ]; then |
---|
| 116 | echo ${new_file} >> ${IGCM_TMP}/${$}.debug_list_${i}.txt |
---|
| 117 | else |
---|
| 118 | ref=${new_ref} |
---|
| 119 | (( i = $i + 1 )) |
---|
| 120 | echo ${new_file} >> ${IGCM_TMP}/${$}.debug_list_${i}.txt |
---|
| 121 | fi |
---|
| 122 | done |
---|
| 123 | |
---|
| 124 | j=1 |
---|
| 125 | while [[ $j -le $i ]]; do |
---|
| 126 | |
---|
| 127 | |
---|
[1728] | 128 | ### 2- creer les listes de fichiers par periode #### |
---|
[1878] | 129 | DEM_log -1 "Creation des listes de fichiers par periode" |
---|
[1728] | 130 | ### 2.1- extraire l'annee et le mois de DateBegin ### |
---|
[1878] | 131 | date_begin=${DateBegin} |
---|
| 132 | date_end=${DateEnd} |
---|
[2045] | 133 | |
---|
[1878] | 134 | year_begin=$(echo ${date_begin} | cut -c 1-4 ) |
---|
| 135 | month_begin=$(echo ${date_begin} | cut -c 5-6 ) |
---|
| 136 | year_end=$(echo ${date_end} | cut -c 1-4 ) |
---|
| 137 | month_end=$(echo ${date_end} | cut -c 5-6 ) |
---|
[1728] | 138 | |
---|
| 139 | |
---|
| 140 | ### 2.2- creation des listes ### |
---|
[1878] | 141 | date_begin_pack=${date_begin} |
---|
| 142 | date_end_simulation=${date_end} |
---|
[1728] | 143 | |
---|
[1878] | 144 | month_begin_pack=${month_begin} |
---|
| 145 | year_begin_pack=${year_begin} |
---|
[1728] | 146 | |
---|
[1878] | 147 | number_pack=1 |
---|
[1728] | 148 | |
---|
[1878] | 149 | while [ ${date_begin_pack} -le ${date_end_simulation} ] |
---|
| 150 | do |
---|
[1728] | 151 | |
---|
[1878] | 152 | DEM_log -1 "On calcule la date de fin du pack " |
---|
| 153 | month_end_pack=${month_begin_pack} |
---|
| 154 | year_end_pack=`expr ${year_begin_pack} + ${period_pack}` |
---|
[2045] | 155 | |
---|
[1878] | 156 | date_end_pack=${year_end_pack}${month_end_pack}01 |
---|
[2045] | 157 | for file in `awk '{print $1}' ${IGCM_TMP}/${$}.debug_list_${j}.txt`; do |
---|
| 158 | extract_date_file=`echo ${file} | sed -e "s/.*\${JobName}_//"` |
---|
| 159 | date_file=`echo ${extract_date_file}| sed 's/\([0-9]\{8\}\)_.*$/\1/g'` |
---|
| 160 | if [[ "x${date_file}" != "x" && ! -n ${date_file//[0-9]/} ]]; then |
---|
| 161 | if [ ${date_file} -lt ${date_end_pack} ] |
---|
| 162 | then |
---|
| 163 | if [ ${date_file} -ge ${date_begin_pack} ] |
---|
[1878] | 164 | then |
---|
[2045] | 165 | echo ${file} >> ${IGCM_TMP}/${$}.liste_pack_debug_${number_pack}.txt |
---|
| 166 | grep -v ${file} ${IGCM_TMP}/${$}.debug_list_${j}.txt > ${IGCM_TMP}/${$}.debug_list_${j}.txt.tmp |
---|
| 167 | mv ${IGCM_TMP}/${$}.debug_list_${j}.txt.tmp ${IGCM_TMP}/${$}.debug_list_${j}.txt |
---|
| 168 | |
---|
| 169 | fi |
---|
| 170 | fi |
---|
| 171 | fi |
---|
| 172 | if [ ${date_file} -gt ${date_end_pack} ] |
---|
| 173 | then |
---|
| 174 | break |
---|
| 175 | fi |
---|
| 176 | |
---|
| 177 | done |
---|
| 178 | month_begin_pack=${month_end_pack} |
---|
| 179 | year_begin_pack=${year_end_pack} |
---|
| 180 | |
---|
| 181 | date_begin_pack=${year_begin_pack}${month_begin_pack}01 |
---|
| 182 | |
---|
| 183 | number_pack=`expr ${number_pack} + 1` |
---|
| 184 | done |
---|
| 185 | |
---|
| 186 | ((j = $j + 1 )) |
---|
| 187 | done |
---|
| 188 | |
---|
| 189 | compt_pack=1 |
---|
| 190 | while [[ $compt_pack -le $number_pack ]]; do |
---|
| 191 | |
---|
[1728] | 192 | #on archive les debug - le nom de l'archive contiendra ${yearbegin}${monthbegin}_${yearend}${monthend} |
---|
| 193 | # end etant la date du dernier fichier contenu et non pas la premiere date suivant |
---|
| 194 | DEM_log -1 "Recherche de la date de fin reel pour nommer l'archive " |
---|
| 195 | #On classe par ordre alphabetique les fichiers contenus dans liste_pack_debug |
---|
| 196 | #la date du dernier fichier donnera la date de fin du pack |
---|
[2045] | 197 | if [[ -f ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt ]] ; then |
---|
| 198 | sort ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt > ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt.tmp |
---|
[1922] | 199 | |
---|
[2045] | 200 | first_file=$(head -n 1 ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt.tmp ) |
---|
[1922] | 201 | extract_date_file=$( echo ${first_file} | sed -e "s/.*${JobName}_//" ) |
---|
| 202 | DateBegin_Debug=$(echo ${extract_date_file}| sed 's%\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
| 203 | |
---|
[2045] | 204 | last_file=$(tail -n 1 ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt.tmp ) |
---|
[1728] | 205 | extract_date_file=$( echo ${last_file} | sed -e "s/.*${JobName}_//" ) |
---|
[1979] | 206 | DateEnd_Debug=$( echo ${extract_date_file}| sed 's%.*\([0-9]\{8\}\)_.*$%\1%g' ) |
---|
[2045] | 207 | mv ${IGCM_TMP}/${$}.liste_pack_debug_${compt_pack}.txt.tmp ${DEBUG_TAR}/${JobName}_debug_${DateBegin_Debug}_${DateEnd_Debug}.list |
---|
[2022] | 208 | fi |
---|
[1728] | 209 | |
---|
| 210 | |
---|
| 211 | |
---|
[1924] | 212 | DEM_log -1 "On definit le datebegin de la prochaine periode pack" |
---|
| 213 | #on definit la periode pack suivante |
---|
[1728] | 214 | |
---|
[2045] | 215 | compt_pack=`expr ${compt_pack} + 1` |
---|
[1728] | 216 | done |
---|
| 217 | |
---|
[1878] | 218 | fi |
---|
[1728] | 219 | |
---|
| 220 | cd ${EXE_DIR} |
---|
[1822] | 221 | |
---|
[1924] | 222 | # gpdebug : le script n a pas rencontre d'erreur. On l'inscrit dans le fichier de suivi |
---|
[1822] | 223 | simuMonitoring_OK "$MonitoringInfo" "$config_card" |
---|