source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 39

Last change on this file since 39 was 39, checked in by sdipsl, 16 years ago

SD : Add sleep 60 in function IGCM_sys_Get_Master to prevent NFS problem

File size: 32.8 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Christian Laguerre
5# Contact: Martial.Mancip_ipsl.jussieu.fr
6# $Date: 2008-05-29 21:29:09 +0200 (Thu, 29 May 2008) $
7# $Author: laguerre $
8# $Revision: 7 $
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11# History:
12# Modification:
13#
14#**************************************************************
15
16#=========================================================
17# The documentation of this file can be automatically generated
18# if you use the prefix #D- for comments to be extracted.
19# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
20#=========================================================
21
22#D-#==================================================
23#D-LibIGCM_sys for obelix
24#D-#==================================================
25#D-
26#D- This ksh library if a layer under some usefull
27#D-environment variables and shell commands.
28#D-All those definitions depend on host particularities.
29#D-It manages a stack mechanism and test validity of operations.
30#D-All function described bellow must be prefixed by IGCM_sys.
31
32#====================================================
33# libIGCM_sys PARAMETERS
34#====================================================
35
36#=====================================================
37# set DEBUG_sys to true to output calls of function
38typeset -r DEBUG_sys=${DEBUG_sys:=true}
39
40#=====================================================
41# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
42typeset -r DRYRUN=${DRYRUN:=0}
43
44# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
45# -------------------------------------------------------------------------------------
46# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
47# |          |  Cp/Exe param files |            |  Chmod  |                           |
48# |          |      Qsub           |            |         |                           |
49# -------------------------------------------------------------------------------------
50# |    0     |       yes           |    yes     |  yes    |      yes                  |
51# -------------------------------------------------------------------------------------
52# |    1     |       yes           |    yes     |  yes    |      no                   |
53# -------------------------------------------------------------------------------------
54# |    2     |       yes           |    yes     |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56# |    3     |       yes           |    no      |  no     |      no                   |
57# -------------------------------------------------------------------------------------
58
59#=====================================================
60# Global Variables :
61#=====================================================
62# Language : "fr" or "en"
63typeset -r MYLANG="fr"
64
65#=====================================================
66# Host and user names
67# $hostname ou hostname
68typeset -r HOST=$( hostname )
69# $username ou whoami
70typeset -r LOGIN=$( whoami )
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79# RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-Lt -v"
81
82#====================================================
83# Source Ferret
84. /home/users/brock/.atlas_env_asterix_ksh
85
86#=========================================================
87# Host specific DIRECTORIES
88#====================================================
89
90#====================================================
91#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
92typeset -r R_EXE="${MODIPSL}/bin"
93
94#====================================================
95#- libIGCM_POST
96typeset -r libIGCM_POST=${libIGCM}
97
98#====================================================
99#- SCRATCHDIR (=> ${R_DONNEES})
100typeset -r SCRATCHDIR=/tmp
101
102#====================================================
103#- SUBMIT_DIR : submission dir
104typeset -r SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
105#====================================================
106#- ARCHIVE
107typeset -r ARCHIVE=/home/scratch01/${LOGIN}
108
109#====================================================
110#- IN
111typeset -r R_IN=${R_IN:=${ARCHIVE}/${LOGIN}/IGCM}
112
113#====================================================
114#- OUT
115typeset -r R_OUT=${ARCHIVE}/${LOGIN}/IGCM_OUT
116
117#====================================================
118#- OUT_POST
119typeset -r R_OUT_POST=${R_OUT}
120
121#====================================================
122#- RUN_DIR_PATH : Temporary working directory (=> TMP)
123typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/tmp$$}
124#typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/home/orchidee_ns/${LOGIN}/tmp$$}
125
126#====================================================
127#- HOST_MPIRUN_COMMAND
128typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
129
130#=========================================================
131#- Add "time" before mpirun command
132MPIRUN_COMMAND="time "${MPIRUN_COMMAND}
133echo ${MPIRUN_COMMAND}
134
135#D-#==================================================
136#D-function IGCM_sys_RshMaster
137#D-* Purpose: Master rsh command
138#D-* Examples:
139#D-
140function IGCM_sys_RshMaster {
141    IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
142    ssh ${HOST} /bin/ksh  <<-EOF
143    export libIGCM=${libIGCM}
144    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
145    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
146    ${@}
147EOF
148    if [ $? -gt 0 ] ; then
149        echo "IGCM_sys_RshMaster : erreur."
150        IGCM_debug_Exit "IGCM_sys_RshMaster"
151    fi
152    IGCM_debug_PopStack "IGCM_sys_RshMaster"
153}
154
155#D-#==================================================
156#D-function IGCM_sys_RshArchive
157#D-* Purpose: Archive rsh command
158#D-* Examples:
159#D-
160function IGCM_sys_RshArchive {
161    IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
162    /bin/ksh ${@}
163    if [ $? -gt 0 ] ; then
164        echo "IGCM_sys_RshArchive : erreur."
165        IGCM_debug_Exit "IGCM_sys_RshArchive"
166    fi
167    IGCM_debug_PopStack "IGCM_sys_RshArchive"
168}
169
170#D-#==================================================
171#D-function IGCM_sys_RshPost
172#D-* Purpose: Master rsh command
173#D-* Examples:
174#D-
175(( RshPNum = 0 ))
176function IGCM_sys_RshPost {
177    IGCM_debug_PushStack "IGCM_sys_RshPost" $@
178    if ( $DEBUG_sys ) ; then
179        echo "IGCM_sys_RshPost :" $@
180    fi
181    #ssh ${HOST} exec /bin/ksh -vx $@ > out_RshPost.${RshPNum}
182    ssh ${HOST} exec /bin/ksh $@ > out_RshPost.${RshPNum}
183    if [ $? -gt 0 ] ; then
184        echo "IGCM_sys_RshPost : erreur."
185        IGCM_debug_Exit "IGCM_sys_RshPost"
186    fi
187    (( RshPNum = RshPNum + 1 ))
188    IGCM_debug_PopStack "IGCM_sys_RshPost"
189}
190
191#D-#==================================================
192#D-function IGCM_sys_Mkdir
193#D-* Purpose: Master locale mkdir command
194#D-* Examples:
195#D-
196function IGCM_sys_Mkdir {
197    IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
198    if ( $DEBUG_sys ) ; then
199        echo "IGCM_sys_Mkdir :" $@
200    fi
201    if [ ! -d ${1} ]; then
202        \mkdir -p $1
203        if [ $? -gt 0 ] ; then
204            echo "IGCM_sys_Mkdir : erreur."
205            IGCM_debug_Exit "IGCM_sys_Mkdir"
206        fi
207    fi
208    # vérification :
209    if [ ! -d ${1} ] ; then
210        echo "IGCM_sys_Mkdir : erreur."
211        IGCM_debug_Exit "IGCM_sys_Mkdir"
212    fi
213    IGCM_debug_PopStack "IGCM_sys_Mkdir"
214}
215
216#D-#==================================================
217#D-function IGCM_sys_MkdirArchive
218#D-* Purpose: Mkdir on Archive
219#D-* Examples:
220#D-
221function IGCM_sys_MkdirArchive {
222    IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
223    if ( $DEBUG_sys ) ; then
224        echo "IGCM_sys_MkdirArchive :" $@
225    fi
226    #- creation de repertoire sur le serveur fichier
227    if [ ! -d ${1} ]; then 
228        \mkdir -p $1
229        if [ $? -gt 0 ] ; then
230            echo "IGCM_sys_MkdirArchive : erreur."
231            IGCM_debug_Exit "IGCM_sys_MkdirArchive"
232        fi
233    fi
234#    vérification ?? :
235    if [ ! -d ${1} ] ; then
236        echo "IGCM_sys_MkdirArchive : erreur."
237        IGCM_debug_Exit "IGCM_sys_MkdirArchive"
238    fi
239    IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
240}
241
242#D-#==================================================
243#D-function IGCM_sys_MkdirWork
244#D-* Purpose: Mkdir on Work
245#D-* Examples:
246#D-
247function IGCM_sys_MkdirWork {
248    IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
249    if ( $DEBUG_sys ) ; then
250        echo "IGCM_sys_MkdirWork :" $@
251    fi
252    #- creation de repertoire sur le serveur fichier
253    if [ ! -d ${1} ]; then 
254        \mkdir -p $1
255        if [ $? -gt 0 ] ; then
256            echo "IGCM_sys_MkdirWork : erreur."
257            IGCM_debug_Exit "IGCM_sys_MkdirWork"
258        fi
259    fi
260    # vérification ?? :
261    if [ ! -d ${1} ] ; then
262        echo "IGCM_sys_MkdirWork : erreur."
263        IGCM_debug_Exit "IGCM_sys_MkdirWork"
264    fi
265    IGCM_debug_PopStack "IGCM_sys_MkdirWork"
266}
267IGCM_sys_MkdirWork ${RUN_DIR_PATH}
268echo "RUN_DIR_PATH ${RUN_DIR_PATH} ok."
269
270#D-#==================================================
271#D-function IGCM_sys_Cd
272#D-* Purpose: master cd command
273#D-* Examples:
274#D-
275function IGCM_sys_Cd {
276    IGCM_debug_PushStack "IGCM_sys_Cd" $@
277    if ( $DEBUG_sys ) ; then
278        echo "IGCM_sys_Cd :" $@
279    fi
280    \cd $1
281    if [ $? -gt 0 ] ; then
282        echo "IGCM_sys_Cd : erreur."
283        IGCM_debug_Exit "IGCM_sys_Cd"
284    fi
285    IGCM_debug_PopStack "IGCM_sys_Cd"
286}
287
288#D-#==================================================
289#D-function IGCM_sys_Chmod
290#D-* Purpose: Chmod
291#D-* Examples:
292#D-
293function IGCM_sys_Chmod {
294    IGCM_debug_PushStack "IGCM_sys_Chmod" $@
295    if ( $DEBUG_sys ) ; then
296        echo "IGCM_sys_Chmod :" $@
297    fi
298    if [ $DRYRUN -le 1 ]; then
299        \chmod $@
300        if [ $? -gt 0 ] ; then
301            echo "IGCM_sys_Chmod : erreur."
302            IGCM_debug_Exit "IGCM_sys_Chmod"
303        fi
304    else
305        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
306    fi
307    IGCM_debug_PopStack "IGCM_sys_Chmod"
308}
309
310#D-#==================================================
311#D-function IGCM_sys_FileSize
312#D-* Purpose: Filesize
313#D-* Examples:
314#D-
315function IGCM_sys_FileSize {
316    IGCM_debug_PushStack "IGCM_sys_FileSize" $@
317
318    typeset sizeF
319    set +A sizeF -- $( ls -la ${1} )
320    if [ $? -gt 0 ] ; then
321        IGCM_debug_Exit "IGCM_sys_FileSize"
322    fi
323    eval ${2}=${sizeF[4]}
324
325    IGCM_debug_PopStack "IGCM_sys_FileSize"
326}
327
328#D-#==================================================
329#D-function IGCM_sys_TestDir
330#D-* Purpose: Test Directory that must exists
331#D-* Examples:
332#D-
333function IGCM_sys_TestDir {
334    IGCM_debug_PushStack "IGCM_sys_TestDir" $@
335    if ( $DEBUG_sys ) ; then
336        echo "IGCM_sys_TestDir :" $@
337    fi
338    if [ ! -d ${1} ]; then
339        echo "IGCM_sys_TestDir : Directory $1 does not exist."
340        IGCM_debug_Exit "IGCM_sys_TestDir"
341    fi
342    IGCM_debug_PopStack "IGCM_sys_TestDir"
343}
344
345#D-#==================================================
346#D-function IGCM_sys_TestDirArchive
347#D-* Purpose: Test Directory that must exists on Archive
348#D-* Examples:
349#D-
350function IGCM_sys_TestDirArchive {
351    IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
352    if ( $DEBUG_sys ) ; then
353        echo "IGCM_sys_TestDirArchive :" $@
354    fi
355    if [ ! -d ${1} ]; then
356        echo "IGCM_sys_TestDirArchive : Directory $1 does not exist on ${ARCHIVE}."
357        IGCM_debug_Exit "IGCM_sys_TestDirArchive"
358    fi
359    IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
360}
361
362#D-#==================================================
363#D-function IGCM_sys_TestFileArchive
364#D-* Purpose: Test file that must NOT EXISTS on Archive
365#D-* Examples:
366#D-
367function IGCM_sys_TestFileArchive {
368    IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
369    if ( $DEBUG_sys ) ; then
370        echo "IGCM_sys_TestFileArchive :" $@
371    fi
372    if [ ! -f ${1} ]; then
373        IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
374        return 1
375    else
376        IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
377        return 0
378    fi
379}
380
381#D-#==================================================
382#D-function IGCM_sys_Tree
383#D-* Purpose: Tree directories with files on ${ARCHIVE}
384#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
385#D-
386function IGCM_sys_Tree {
387    IGCM_debug_PushStack "IGCM_sys_Tree" $@
388    if ( $DEBUG_sys ) ; then
389        echo "IGCM_sys_Tree :" $@
390    fi
391
392    \tree -f $@
393
394    IGCM_debug_PopStack "IGCM_sys_Tree"
395}
396
397#D-#==================================================
398#D-function IGCM_sys_Tar
399#D-* Purpose: master un-tar command
400#D-* Examples:
401#D-
402function IGCM_sys_Tar {
403    IGCM_debug_PushStack "IGCM_sys_Tar" $@
404    if ( $DEBUG_sys ) ; then
405        echo "IGCM_sys_Tar :" $@
406    fi
407    \tar cvf $@
408    if [ $? -gt 0 ] ; then
409        echo "IGCM_sys_Tar : erreur."
410        IGCM_debug_Exit "IGCM_sys_Tar"
411    fi
412    \tar tvf $1
413
414    IGCM_debug_PopStack "IGCM_sys_Tar"
415}
416
417#D-#==================================================
418#D-function IGCM_sys_UnTar
419#D-* Purpose: master un-tar command
420#D-* Examples:
421#D-
422function IGCM_sys_UnTar {
423    IGCM_debug_PushStack "IGCM_sys_UnTar" $@
424    if ( $DEBUG_sys ) ; then
425        echo "IGCM_sys_UnTar :" $@
426    fi
427    \tar xvf $1
428    if [ $? -gt 0 ] ; then
429        echo "IGCM_sys_UnTar : erreur."
430        IGCM_debug_Exit "IGCM_sys_UnTar"
431    fi
432    IGCM_debug_PopStack "IGCM_sys_UnTar"
433}
434
435#D-#==================================================
436#D-function IGCM_sys_Qsub
437#D-* Purpose: Qsub new job
438#D-* Examples:
439#D-
440function IGCM_sys_Qsub {
441    IGCM_debug_PushStack "IGCM_sys_Qsub" $@
442    if ( $DEBUG_sys ) ; then
443        echo "IGCM_sys_Qsub :" $@
444    fi
445    /usr/local/bin/qsub -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} < $1
446    if [ $? -gt 0 ] ; then
447        echo "IGCM_sys_Qsub : erreur -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} $@."
448        IGCM_debug_Exit "IGCM_sys_Qsub"
449    fi
450    IGCM_debug_PopStack "IGCM_sys_Qsub"
451}
452
453#D-#==================================================
454#D-function IGCM_sys_QsubPost
455#D-* Purpose: Qsub new job on scalaire
456#D-* Examples:
457#D-
458function IGCM_sys_QsubPost {
459    IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
460    if ( $DEBUG_sys ) ; then
461        echo "IGCM_sys_QsubPost :" $@
462    fi
463    /usr/local/bin/qsub -q medium -o ${POST_DIR}/$1.${PeriodDateEnd}.out ${libIGCM_POST}/$1.job -v ${listVarEnv}
464    if [ $? -gt 0 ] ; then
465        echo "IGCM_sys_QsubPost : erreur " $@
466        IGCM_debug_Exit "IGCM_sys_QsubPost"
467    fi
468    IGCM_debug_PopStack "IGCM_sys_QsubPost"
469}
470
471#D-*************************
472#D- File transfer functions
473#D-*************************
474#D-
475
476#D-#==================================================
477#D-function IGCM_sys_Rsync_out
478#D-* Purpose: treat return val of rsync
479#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
480#D-  Error values and explanations can depend on your system version.
481function IGCM_sys_Rsync_out {
482    RET=$1
483    if [ ! $RET ] ; then
484        echo "rsync error !"
485    fi
486
487    if [ $MYLANG = "fr" ]; then
488        case $RET in
489            0)  return ;;
490            1)  echo "Erreur de rsync ; RERR_SYNTAX : "
491                echo "Erreur de syntaxe ou d'utilisation."
492                return;;
493            2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
494                echo "Incompatibilité de protocole."
495                return;;
496            3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
497                echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
498                echo "répertoires"
499                return;;
500            4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
501                echo "Action demandée non supportée : une tentative de manipulation de"
502                echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
503                echo "été faite ; ou une option qui est supportée par le  client  mais"
504                echo "pas par le serveur a été spécifiée."
505                return;;
506            10) echo "Erreur de rsync ; RERR_SOCKETIO"
507                echo "Erreur dans le socket d'entrée sortie"
508                return;;
509            11) echo "Erreur de rsync ; RERR_FILEIO"
510                echo "Erreur d'entrée sortie fichier"
511                return;;
512            12) echo "Erreur de rsync ; RERR_STREAMIO"
513                echo "Erreur dans flux de donnée du protocole rsync"
514                return;;
515            13) echo "Erreur de rsync ; RERR_MESSAGEIO"
516                echo "Erreur avec les diagnostics du programme"
517                return;;
518            14) echo "Erreur de rsync ; RERR_IPC"
519                echo "Erreur dans le code IPC"
520                return;;
521            20) echo "Erreur de rsync ; RERR_SIGNAL"
522                echo "SIGUSR1 ou SIGINT reçu"
523                return;;
524            21) echo "Erreur de rsync ; RERR_WAITCHILD"
525                echo "Une erreur retournée par waitpid()"
526                return;;
527            22) echo "Erreur de rsync ; RERR_MALLOC"
528                echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
529                return;;
530            23) echo ""
531                echo "Erreur fichier inexistant"
532                return;;
533            30) echo "Erreur de rsync ; RERR_TIMEOUT"
534                echo "Temps d'attente écoulé dans l'envoi/réception de données"
535                return;;
536            *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
537                return;;
538        esac
539    elif [ $MYLANG = "en" ] ; then
540        case $RET in
541            0)  return;;               
542            1)  echo "rsync error : Syntax or usage error "
543                return;;
544            2)  echo "rsync error : Protocol incompatibility "
545                return;;
546            3)  echo "rsync error : Errors selecting input/output files, dirs"
547                return;;
548            4)  echo "rsync error : Requested action not supported: an attempt"
549                echo "was made to manipulate 64-bit files on a platform that cannot support"
550                echo "them; or an option was specified that is supported by the client and"
551                echo "not by the server."
552                return;;
553            5)  echo "rsync error : Error starting client-server protocol"
554                return;;
555            10) echo "rsync error : Error in socket I/O "
556                return;;
557            11) echo "rsync error : Error in file I/O "
558                return;;
559            12) echo "rsync error : Error in rsync protocol data stream "
560                return;;
561            13) echo "rsync error : Errors with program diagnostics "
562                return;;
563            14) echo "rsync error : Error in IPC code "
564                return;;
565            20) echo "rsync error : Received SIGUSR1 or SIGINT "
566                return;;
567            21) echo "rsync error : Some error returned by waitpid() "
568                return;;
569            22) echo "rsync error : Error allocating core memory buffers "
570                return;;
571            23) echo "rsync error : Partial transfer due to error"
572                return;;
573            24) echo "rsync error : Partial transfer due to vanished source files"
574                return;;
575            30) echo "rsync error : Timeout in data send/receive "
576                return;;
577            *)  echo "rsync error : return code of rsync unknown :" $RET
578                return;;
579        esac
580    else
581        echo "unknown language $MYLANG."
582        return
583    fi
584}
585   
586#D-#==================================================
587#D-function IGCM_sys_Cp
588#D-* Purpose: generic cp
589#D-* Examples:
590#D-
591function IGCM_sys_Cp {
592    IGCM_debug_PushStack "IGCM_sys_Cp" $@
593    if ( $DEBUG_sys ) ; then
594        echo "IGCM_sys_Cp :" $@
595    fi
596
597    typeset RET
598
599    echo cp --preserve=timestamps $@ > out_rsync 2>&1
600    \cp --preserve=timestamps $@ >> out_rsync 2>&1
601    RET=$?
602   
603    if [ ${RET} -gt 0 ] ; then
604        echo "IGCM_sys_Cp : error."
605        cat out_rsync
606        IGCM_debug_Exit "IGCM_sys_Cp"
607    fi
608    IGCM_debug_PopStack "IGCM_sys_Cp"
609}
610
611#D-#==================================================
612#D-function IGCM_sys_Rm
613#D-* Purpose: generic rm
614#D-* Examples:
615#D-
616function IGCM_sys_Rm {
617    IGCM_debug_PushStack "IGCM_sys_Rm" $@
618    if ( $DEBUG_sys ) ; then
619        echo "IGCM_sys_Rm :" $@
620    fi
621
622    typeset RET
623
624    echo rm $@ > out_rsync 2>&1
625    \rm $@ >> out_rsync 2>&1
626    RET=$?
627   
628    if [ ${RET} -gt 0 ] ; then
629        echo "IGCM_sys_Rm : error."
630        cat out_rsync
631        IGCM_debug_Exit "IGCM_sys_Rm"
632    fi
633    IGCM_debug_PopStack "IGCM_sys_Rm"
634}
635
636#D-#==================================================
637#D-function IGCM_sys_Mv
638#D-* Purpose: generic move
639#D-* Examples:
640#D-
641function IGCM_sys_Mv {
642    IGCM_debug_PushStack "IGCM_sys_Mv" $@
643    if ( $DEBUG_sys ) ; then
644        echo "IGCM_sys_Mv :" $@
645    fi
646
647    typeset RET
648
649    echo mv $@ > out_rsync 2>&1
650    \mv $@ >> out_rsync 2>&1
651    RET=$?
652   
653    if [ ${RET} -gt 0 ] ; then
654        echo "IGCM_sys_Mv : error in mv."
655        cat out_rsync
656        IGCM_debug_Exit "IGCM_sys_Mv"
657    fi
658
659    IGCM_debug_PopStack "IGCM_sys_Mv"
660}
661
662#D-#==================================================
663#D-function IGCM_sys_Put_Dir
664#D-* Purpose: Copy a complete directory on $(ARCHIVE)
665#D-* Examples:
666#D-
667function IGCM_sys_Put_Dir {
668    IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
669    if ( $DEBUG_sys ) ; then
670        echo "IGCM_sys_Put_Dir :" $@
671    fi
672    if [ $DRYRUN = 0 ]; then
673        if [ ! -d ${1} ] ; then
674            echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
675            IGCM_debug_PopStack "IGCM_sys_Put_Dir"
676            return
677        fi
678
679        typeset RET
680
681        # Only if we use rsync
682        #IGCM_sys_TestDirArchive $( dirname $2 )
683        #
684        #USUAL WAY
685        \cp -R $1 $2 > out_rsync 2>&1
686        RET=$?
687
688        if [ ${RET} -gt 0 ] ; then
689            echo "IGCM_sys_Put_Dir : error."
690            cat out_rsync
691            IGCM_debug_Exit "IGCM_sys_Put_Dir"
692        fi
693    else
694        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
695    fi
696    IGCM_debug_PopStack "IGCM_sys_Put_Dir"
697}
698
699#D-#==================================================
700#D-function IGCM_sys_Get_Dir
701#D-* Purpose: Copy a complete directory from $(ARCHIVE)
702#D-* Examples:
703#D-
704function IGCM_sys_Get_Dir {
705    IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
706    if ( $DEBUG_sys ) ; then
707        echo "IGCM_sys_Get_Dir :" $@
708    fi
709    if [ $DRYRUN = 0 ]; then
710        if [ ! -d ${1} ] ; then
711            echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
712            IGCM_debug_PopStack "IGCM_sys_Get_Dir"
713            return
714        fi
715
716        typeset RET
717
718        #USUAL WAY
719        \cp -R $1 $2 > out_rsync 2>&1
720        RET=$?
721
722        if [ ${RET} -gt 0 ] ; then
723            echo "IGCM_sys_Get_Dir : error."
724            cat out_rsync
725            IGCM_debug_Exit "IGCM_sys_Get_Dir"
726        fi
727    else
728        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
729    fi
730    IGCM_debug_PopStack "IGCM_sys_Get_Dir"
731}
732
733#D-#==================================================
734#D-function IGCM_sys_Get_Master
735#D-* Purpose: Copy a complete directory from MASTER filesystem
736#D-* Examples:
737#D-
738function IGCM_sys_Get_Master {
739    IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
740    if ( $DEBUG_sys ) ; then
741        echo "IGCM_sys_Get_Master :" $@
742    fi
743    if [ $DRYRUN = 0 ]; then
744        if [ ! -d ${1} ] ; then
745            echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
746            IGCM_debug_PopStack "IGCM_sys_Get_Master"
747            return
748        fi
749
750        typeset RET
751        sleep 60
752
753        #USUAL WAY
754        cp -R $1 $2 > out_rsync 2>&1
755        RET=$?
756
757        if [ ${RET} -gt 0 ] ; then
758            echo "IGCM_sys_Get_Master : error."
759            cat out_rsync
760            IGCM_debug_Exit "IGCM_sys_Get_Master"
761        fi
762    else
763        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
764    fi
765    IGCM_debug_PopStack "IGCM_sys_Get_Master"
766}
767
768#D-#==================================================
769#D-function IGCM_sys_Put_Rest
770#D-* Purpose: commande de transfert des restarts $(ARCHIVE).
771#D-           Quitte si le fichier ou si le répertoire d'arriver n'existe pas.
772#D-* Examples:
773#D-
774function IGCM_sys_Put_Rest {
775    IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
776    if ( $DEBUG_sys ) ; then
777        echo "IGCM_sys_Put_Rest :" $@
778    fi
779    if [ $DRYRUN = 0 ]; then
780
781        IGCM_sys_TestDirArchive $( dirname $2 )
782
783        if [ ! -f ${1} ] ; then
784            echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
785            IGCM_debug_Exit "IGCM_sys_Put_Rest"
786        fi
787        IGCM_sys_Chmod 444 ${1}
788
789        typeset RET
790
791        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
792        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
793        RET=$?
794        IGCM_sys_Rsync_out $RET
795
796        ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
797        (( RET=RET+$? ))
798
799        if [ ${RET} -gt 0 ] ; then
800            echo "IGCM_sys_Put_Rest : error."
801            cat out_rsync
802            IGCM_debug_Exit "IGCM_sys_Put_Rest"
803        fi
804    else
805        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
806    fi
807    IGCM_debug_PopStack "IGCM_sys_Put_Rest"
808}
809
810#D-#==================================================
811#D-function IGCM_sys_Put_Out
812#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
813#D-* Examples:
814#D-
815function IGCM_sys_Put_Out {
816    IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
817    if ( $DEBUG_sys ) ; then
818        echo "IGCM_sys_Put_Out :" $@
819    fi
820    if [ $DRYRUN = 0 ]; then
821        if [ -f ${1} ] ; then
822            if [ ! -d $( dirname $2 ) ] ; then
823                IGCM_sys_MkdirArchive $( dirname $2 )
824            fi
825        else
826            echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
827            IGCM_debug_PopStack "IGCM_sys_Put_Out"
828            return 1
829        fi
830
831        typeset RET
832        #
833        IGCM_sys_Chmod 444 ${1}
834        #
835
836        echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
837        ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
838        RET=$?
839        IGCM_sys_Rsync_out $RET
840
841        ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
842        (( RET=RET+$? ))
843
844        if [ ${RET} -gt 0 ] ; then
845            echo "IGCM_sys_Put_Out : error."
846            cat out_rsync
847            IGCM_debug_Exit "IGCM_sys_Put_Out"
848        fi
849    else
850        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
851    fi
852    IGCM_debug_PopStack "IGCM_sys_Put_Out"
853    return 0
854}
855
856#D-#==================================================
857#D-function IGCM_sys_Get
858#D-* Purpose: Get a file from ${ARCHIVE}
859#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
860#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
861function IGCM_sys_Get {
862    IGCM_debug_PushStack "IGCM_sys_Get" $@
863
864    typeset DEST RET dm_liste ifile target
865
866    if ( $DEBUG_sys ) ; then
867        echo "IGCM_sys_Get :" $@
868    fi
869    if [ $DRYRUN -le 2 ]; then
870        if [ X${1} = X'/l' ] ; then
871            # test if the first file is present in the old computation :
872            eval set +A dm_liste \${${2}}
873        else
874            dm_liste=${1}
875        fi
876        eval DEST=\${${#}}
877
878        # test if the (first) file is present in the old computation :
879        IGCM_sys_TestFileArchive ${dm_liste[0]}
880        RET=$?
881        if [ ${RET} -gt 0 ] ; then
882            echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
883            IGCM_debug_Exit "IGCM_sys_Get"
884            return
885        fi
886
887        (( RET=0 ))
888        for target in ${dm_liste[*]} ; do
889          \cp ${target} ${DEST} >> out_rsync 2>&1
890          (( RET=RET+$? ))
891        done
892
893#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
894#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
895#       RET=$?
896#       IGCM_sys_Rsync_out $RET
897
898#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
899#       (( RET=RET+$? ))
900
901        if [ ${RET} -gt 0 ] ; then
902            echo "IGCM_sys_Get : copy error."
903            cat out_rsync
904            IGCM_debug_Exit "IGCM_sys_Get"
905        fi
906    else
907        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
908    fi
909    IGCM_debug_PopStack "IGCM_sys_Get"
910}
911
912#D-#==================================================
913#D-function IGCM_sys_Put_Dods
914#D-* Purpose: DO NOTHING ! Put $(ARCHIVE) files on DODS internet protocole.
915#D-* Examples:
916#D-
917function IGCM_sys_Put_Dods {
918    IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
919    if ( $DEBUG_sys ) ; then
920        echo "IGCM_sys_Put_Dods :" $@
921    fi
922    if [ $DRYRUN = 0 ]; then
923        if [ ! -f ${1} ] ; then
924            echo "WARNING : IGCM_sys_Put_Dods ${1} DOES NOT EXIST ."
925            IGCM_debug_PopStack "IGCM_sys_Put_Dods"
926            return
927        fi
928        #DO NOTHING
929    else
930        ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
931    fi
932    IGCM_debug_PopStack "IGCM_sys_Put_Dods"
933}
934
935############################################################## A REVOIR !!
936
937#D-#==================================================
938#D-function IGCM_sys_Rapatrie
939#D-* Purpose: Rapatrie
940#D-* Examples:
941#D-
942function IGCM_sys_Rapatrie {
943    IGCM_debug_PushStack "IGCM_sys_Rapatrie" $@
944    if ( $DEBUG_sys ) ; then
945        echo "IGCM_sys_Rapatrie :" $@
946    fi
947
948    typeset RET=0
949
950    IGCM_sys_Get ${R_STOCKAGE}/$2 $1 ;
951    let $(( RET=RET+$? ))
952    IGCM_sys_Cd $1 ;
953    let $(( RET=RET+$? ))
954    IGCM_sys_UnTar $2 ;
955    let $(( RET=RET+$? ))
956
957    if [ ${RET} -gt 0 ] ; then
958        echo "IGCM_sys_Rapatrie : erreur."
959        IGCM_debug_Exit "IGCM_sys_Rapatrie"
960    fi
961    IGCM_debug_PopStack "IGCM_sys_Rapatrie"
962}
963
964############################################################## A FINIR !!
965
966#D-#==================================================
967#D-function IGCM_sys_GetDate_FichWork
968#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
969#D-* Examples:
970#D-
971function IGCM_sys_GetDate_FichWork {
972    IGCM_debug_PushStack "IGCM_sys_FichWork" $@
973    if ( $DEBUG_sys ) ; then
974        echo "IGCM_sys_GetDate_FichWork :" $@
975    fi
976    # donne la date filesys d'un fichier sur la machine work
977    IGCM_debug_PopStack "IGCM_sys_FichWork"
978}
979
980#D-#==================================================
981#D-function IGCM_sys_GetDate_FichArchive
982#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
983#D-* Examples:
984#D-
985function IGCM_sys_GetDate_FichArchive {
986    IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
987    if ( $DEBUG_sys ) ; then
988        echo "IGCM_sys_GetDate_FichArchive :" $@
989    fi
990    IGCM_debug_PopStack "IGCM_sys_FichArchive"
991}
992
993
994##############################################################
995# REBUILD OPERATOR
996
997function IGCM_sys_rebuild {
998    IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
999    if ( $DEBUG_sys ) ; then
1000        echo "IGCM_sys_rebuild :" $@
1001    fi
1002    rebuild -f -o $@
1003    if [ $? -gt 0 ] ; then
1004       echo "IGCM_sys_rebuild : erreur ${@}."
1005       IGCM_debug_Exit "rebuild"
1006    fi
1007
1008    IGCM_debug_PopStack "IGCM_sys_rebuild"
1009}
1010
1011##############################################################
1012# NCO OPERATOR
1013
1014function IGCM_sys_ncap {
1015    IGCM_debug_PushStack "IGCM_sys_ncap" -- $@
1016    if ( $DEBUG_sys ) ; then
1017        echo "IGCM_sys_ncap :" $@
1018    fi
1019    /usr/local/bin/ncap $@
1020    if [ $? -gt 0 ] ; then
1021       echo "IGCM_sys_ncap : erreur ${@}."
1022#       IGCM_debug_Exit "ncap"
1023    fi
1024
1025    IGCM_debug_PopStack "IGCM_sys_ncap"
1026}
1027
1028ncatted=/usr/local/bin/ncatted
1029# Problem with ksh and string passed in this function to ncatted !
1030# function IGCM_sys_ncatted {
1031#     IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1032#     if ( $DEBUG_sys ) ; then
1033#       echo "IGCM_sys_ncatted :" $@
1034#     fi
1035#     /usr/local/bin/ncatted $@
1036#     if [ $? -gt 0 ] ; then
1037#        echo "IGCM_sys_ncatted : erreur ${@}."
1038#        IGCM_debug_Exit "ncatted"
1039#     fi
1040
1041#     IGCM_debug_PopStack "IGCM_sys_ncatted"
1042# }
1043
1044function IGCM_sys_ncbo {
1045    IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1046    if ( $DEBUG_sys ) ; then
1047        echo "IGCM_sys_ncbo :" $@
1048    fi
1049    /usr/local/bin/ncbo $@
1050    if [ $? -gt 0 ] ; then
1051       echo "IGCM_sys_ncbo : erreur ${@}."
1052#       IGCM_debug_Exit "ncbo"
1053    fi
1054
1055    IGCM_debug_PopStack "IGCM_sys_ncbo"
1056}
1057
1058function IGCM_sys_ncdiff {
1059    IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1060    if ( $DEBUG_sys ) ; then
1061        echo "IGCM_sys_ncdiff :" $@
1062    fi
1063    /usr/local/bin/ncdiff $@
1064    if [ $? -gt 0 ] ; then
1065       echo "IGCM_sys_ncdiff : erreur ${@}."
1066#       IGCM_debug_Exit "ncdiff"
1067    fi
1068
1069    IGCM_debug_PopStack "IGCM_sys_ncdiff"
1070}
1071
1072function IGCM_sys_ncea {
1073    IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1074    if ( $DEBUG_sys ) ; then
1075        echo "IGCM_sys_ncea :" $@
1076    fi
1077    /usr/local/bin/ncea $@
1078    if [ $? -gt 0 ] ; then
1079       echo "IGCM_sys_ncea : erreur ${@}."
1080#       IGCM_debug_Exit "ncea"
1081    fi
1082
1083    IGCM_debug_PopStack "IGCM_sys_ncea"
1084}
1085
1086function IGCM_sys_ncecat {
1087    IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1088    if ( $DEBUG_sys ) ; then
1089        echo "IGCM_sys_ncecat :" $@
1090    fi
1091    /usr/local/bin/ncecat $@
1092    if [ $? -gt 0 ] ; then
1093       echo "IGCM_sys_ncecat : erreur ${@}."
1094#       IGCM_debug_Exit "ncecat"
1095    fi
1096
1097    IGCM_debug_PopStack "IGCM_sys_ncecat"
1098}
1099
1100function IGCM_sys_ncflint {
1101    IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1102    if ( $DEBUG_sys ) ; then
1103        echo "IGCM_sys_ncflint :" $@
1104    fi
1105    /usr/local/bin/ncflint $@
1106    if [ $? -gt 0 ] ; then
1107       echo "IGCM_sys_ncflint : erreur ${@}."
1108#       IGCM_debug_Exit "ncflint"
1109    fi
1110
1111    IGCM_debug_PopStack "IGCM_sys_ncflint"
1112}
1113
1114function IGCM_sys_ncks {
1115    IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1116    if ( $DEBUG_sys ) ; then
1117        echo "IGCM_sys_ncks :" $@
1118    fi
1119    /usr/local/bin/ncks $@
1120    if [ $? -gt 0 ] ; then
1121       echo "IGCM_sys_ncks : erreur ${@}."
1122#       IGCM_debug_Exit "ncks"
1123    fi
1124
1125    IGCM_debug_PopStack "IGCM_sys_ncks"
1126}
1127
1128function IGCM_sys_ncpdq {
1129    IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1130    if ( $DEBUG_sys ) ; then
1131        echo "IGCM_sys_ncpdq :" $@
1132    fi
1133    /usr/local/bin/ncpdq $@
1134    if [ $? -gt 0 ] ; then
1135       echo "IGCM_sys_ncpdq : erreur ${@}."
1136#       IGCM_debug_Exit "ncpdq"
1137    fi
1138
1139    IGCM_debug_PopStack "IGCM_sys_ncpdq"
1140}
1141
1142function IGCM_sys_ncra {
1143    IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1144    if ( $DEBUG_sys ) ; then
1145        echo "IGCM_sys_ncra :" $@
1146    fi
1147    /usr/local/bin/ncra $@
1148    if [ $? -gt 0 ] ; then
1149       echo "IGCM_sys_ncra : erreur ${@}."
1150#       IGCM_debug_Exit "ncra"
1151    fi
1152
1153    IGCM_debug_PopStack "IGCM_sys_ncra"
1154}
1155
1156function IGCM_sys_ncrcat {
1157    IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1158    if ( $DEBUG_sys ) ; then
1159        echo "IGCM_sys_ncrcat :" $@
1160    fi
1161    /usr/local/bin/ncrcat $@
1162    if [ $? -gt 0 ] ; then
1163       echo "IGCM_sys_ncrcat : erreur ${@}."
1164#       IGCM_debug_Exit "ncrcat"
1165    fi
1166
1167    IGCM_debug_PopStack "IGCM_sys_ncrcat"
1168}
1169
1170function IGCM_sys_ncrename {
1171    IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1172    if ( $DEBUG_sys ) ; then
1173        echo "IGCM_sys_ncrename :" $@
1174    fi
1175    /usr/local/bin/ncrename $@
1176    if [ $? -gt 0 ] ; then
1177       echo "IGCM_sys_ncrename : erreur ${@}."
1178#       IGCM_debug_Exit "ncrename"
1179    fi
1180
1181    IGCM_debug_PopStack "IGCM_sys_ncrename"
1182}
1183
1184function IGCM_sys_ncwa {
1185    IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1186    if ( $DEBUG_sys ) ; then
1187        echo "IGCM_sys_ncwa :" $@
1188    fi
1189    /usr/local/bin/ncwa $@
1190    if [ $? -gt 0 ] ; then
1191       echo "IGCM_sys_ncwa : erreur ${@}."
1192#       IGCM_debug_Exit "ncwa"
1193    fi
1194
1195    IGCM_debug_PopStack "IGCM_sys_ncwa"
1196}
1197
1198############################################################
1199# Activate Running Environnment Variables
1200
1201function IGCM_sys_activ_variables {
1202    IGCM_debug_PushStack "IGCM_sys_activ_variables"
1203    if ( $DEBUG_sys ) ; then
1204        echo "IGCM_sys_activ_variables"
1205    fi
1206    IGCM_debug_PopStack "IGCM_sys_activ_variables"
1207}
1208
1209############################################################
1210# Desactivate Running Environnment Variables
1211
1212function IGCM_sys_desactiv_variables {
1213    IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1214    if ( $DEBUG_sys ) ; then
1215        echo "IGCM_sys_desactiv_variables"
1216    fi
1217    IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1218}
1219
1220############################################################
1221# Build run file
1222
1223function IGCM_sys_build_run_file {
1224    IGCM_debug_PushStack "IGCM_sys_build_run_file"
1225    if ( $DEBUG_sys ) ; then
1226        echo "IGCM_sys_build_run_file"
1227    fi
1228    IGCM_debug_PopStack "IGCM_sys_build_run_file"
1229}
Note: See TracBrowser for help on using the repository browser.