source: palm/trunk/SCRIPTS/batch_scp @ 2281

Last change on this file since 2281 was 2261, checked in by raasch, 7 years ago

changes in mrun: unified cycle numbers for output files are used, paths and filenames are allowed to contain arbitrary numbers of dots, archive feature completely removed from the script, nech related parts completely removed, OpenMP bugfix in prognostic_equations

  • Property svn:keywords set to Id
File size: 26.5 KB
Line 
1#! /bin/bash
2
3# batch_scp - script for automatic file/directory transfer using scp
4
5#--------------------------------------------------------------------------------#
6# This file is part of PALM.
7#
8# PALM is free software: you can redistribute it and/or modify it under the terms
9# of the GNU General Public License as published by the Free Software Foundation,
10# either version 3 of the License, or (at your option) any later version.
11#
12# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along with
17# PALM. If not, see <http://www.gnu.org/licenses/>.
18#
19# Copyright 1997-2014  Leibniz Universitaet Hannover
20#--------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
24#
25#
26# Former revisions:
27# -----------------
28# $Id: batch_scp 2261 2017-06-08 14:25:57Z suehring $
29# option usecycle added, script is running under bash now,
30# filenames are allowed to contain arbitrary number of dots "."
31#
32# 1310 2014-03-14 08:01:56Z raasch
33#
34# 1202 2013-07-10 16:22:07Z witha
35# adjustments for Forwind cluster (lcflow): using absolute paths for ssh
36#
37# 1099 2013-02-10 01:47:43Z raasch
38# LANG variable is unset in some ssh calls to guarantee messages in English
39#
40# 1094 2013-02-03 01:52:12Z raasch
41# new option -P for explicit setting of ssh/scp port
42#
43# 1090 2013-02-02 07:06:13Z raasch
44# code put under GPL (PALM 3.9)
45# adjustments for Kyushu-University computing center (lckyut)
46# old changelog messages removed
47#
48# 08/03/11 - Siggi - adjustments for ibmkisti: this machine allows
49#                    outgoing ssh/scp connections only from the
50#                    interactive nodes (gaiad). All ssh/scp traffic is
51#                    done via this interactive node.
52# 04/01/02 - Siggi - first version finished
53# 29/11/01 - Siggi - script development started
54#
55#--------------------------------------------------------------------------------#
56# batch_scp - script for automatic file/directory transfers using scp
57#
58# batch_scp has up to 5 arguments (first 4 are mandatory):
59#               $1 = IP-addres of remote (target) machine
60#               $2 = file to be transferred
61#               $3 = directory of remote machine, where file should be copied to
62#               $4 = filename that file should be given on remote machine
63#               $5 = file extension (optional argument)
64#
65# ATTENTION: problems might occur if directories on remote machine include very
66#            old files for which "ls -al" does give "year" as modification
67#            time instead of "hh:mm". In such a case, batch_scp cannot check the
68#            filename and may not find the file (e.g. if option -g is used).
69#--------------------------------------------------------------------------------#
70
71
72 
73    # VARIABLENVEREINBARUNGEN + DEFAULTWERTE
74 random=$RANDOM
75
76 absolut=false
77 append=false
78 catalog_copy=false
79 check=false
80 delete=false
81 errfile=batch_scp.errfile.$random
82 filelist=filelist.$random
83 get=false
84 local_host=`hostname`
85 local_user=$USER
86 local_wdir=`pwd`
87 locat=normal
88 make_catalog=false
89 overwrite=false
90 print_local_filename=false
91 quote_wait=false
92 remote_user=""
93 silent=false
94 transfermode=binary
95 zyklusnr=""
96 typeset -i iii icycle maxcycle=0 usecycle wait=0
97
98    # FEHLERBEHANDLUNG
99    # BEI EXIT:
100 trap 'if [[ $locat != normal ]]
101       then
102          [[ -f "$filelist" ]]  &&  cat $filelist
103          [[ -f "$errfile"  ]]  &&  cat $errfile
104          rm -rf $filelist $errfile
105          printf " +++ BATCH_SCP terminated \n"
106          printf "     locat     = $locat \n"
107          printf "     arguments = $1 $2 $3 $4 \n\n"
108          exit 1
109       fi' exit
110
111
112    # BEI TERMINAL-BREAK:
113 trap 'rm -rf $filelist $errfile
114       printf " +++ BATCH_SCP terminated \n\n"
115       exit 1
116      ' 2
117
118
119    # SHELLSCRIPT-OPTIONEN EINLESEN
120 while  getopts  :aAbcCdgmnoP:qsu:U:w:  option
121 do
122   case  $option  in
123       (a)   absolut=true;;
124       (A)   append=true;;
125       (b)   transfermode=binary;;
126       (c)   catalog_copy=true;;
127       (C)   check=true;;
128       (d)   delete=true;;
129       (g)   get=true;;
130       (m)   make_catalog=true;;
131       (n)   print_local_filename=true;;  # Option ist nicht dokumentiert !
132       (o)   overwrite=true;;
133       (P)   scp_port=$OPTARG;;
134       (q)   quote_wait=true;;
135       (s)   silent=true;;
136       (u)   remote_user=$OPTARG;;
137       (U)   usecycle=$OPTARG;;
138       (w)   wait=$OPTARG;;
139       (\?)  printf "  +++ option $OPTARG unknown \n"
140             printf "  --> call: batch_scp [-aAbcCdgmnoqsuw] <IP-adress> <localfile> <remotepath> <remotefile>\n"
141             locat=parameter;exit;;
142   esac
143 done
144
145 (( to_shift = $OPTIND - 1 ))
146 shift $to_shift
147
148
149
150 
151    # KURZE AUFRUFBESCHREIBUNG WIRD HIER AUSGEGEBEN
152 if [ "$1" = "?" ]
153 then
154   (printf "\n  *** batch_scp can be called as follows:\n"
155    printf "\n      batch_scp -a -b -d -g -o -q -s -u.. -U.. -w..  <param1> <param2> <param3> <param4>\n"
156    printf "\n      Description of available options:\n"
157    printf "\n      Option  Description                            Default-Value"
158    printf "\n        -a    Filenames are absolute. No cycle-      ---"
159    printf "\n              numbers will be determined"
160    printf "\n        -A    append to destination file             ---"
161    printf "\n        -b    use binary-modus for transfer          ASCII-modus"
162    printf "\n        -c    transfer of directory                  ---"
163    printf "\n        -C    check-Modus, no transfer               ---"
164    printf "\n        -d    file to be transferred will be         ---"
165    printf "\n              deleted after successful transfer"
166    printf "\n        -g    change of transfer direction, i.e.     ---"
167    printf "\n              file will be transferred from"
168    printf "\n              destination host"
169    printf "\n        -o    any existing file will be overwritten  ---"
170    printf "\n        -q    switch on  \"quote wait\"  on          ---"
171    printf "\n              estination host"
172    printf "\n        -s    do not display informative messages    ---"
173    printf "\n        -u    username on remote machine             <username>"
174    printf "\n        -U    cycle number to be used                ---"
175    printf "\n        -w    waiting time in seconds, before trans- 0"
176    printf "\n              fer will be initiated"
177    printf "\n "
178    printf "\n      The positional parameters <param1> - <param4> must be provided at"
179    printf "\n      any time and have the following meaning:"
180    printf "\n        <param1>  -  IP-adress of destination host"
181    printf "\n                     or \"?\"  (creates this outline)"
182    printf "\n        <param2>  -  abs. or rel. path of file to be transferred"
183    printf "\n        <param3>  -  directory (abs.!) on destination host. Special cahracters"
184    printf "\n                     like \~ are allowed but must be quoted by \"."
185    printf "\n        <param4>  -  filename (without path!) on destination host; must not"
186    printf "\n                     be given, if option -c is used."
187    printf "\n      When using option -g, file will be copied from destination host to file"
188    printf "\n      <param2>. In this case, no overwriting is possible.") | more
189    exit
190 fi
191
192
193    # PRUEFEN, OB ALLE ARGUMENTE VORLIEGEN
194 if [[ "$1" = "" ]]
195 then
196    printf " +++ 1. argument missing \n"
197    locat=argument; exit
198 elif [[ "$2" = "" ]]
199 then
200    printf " +++ 2. argument missing \n"
201    locat=argument; exit
202 elif [[ "$3" = "" ]]
203 then
204    printf " +++ 3. argument missing \n"
205    locat=argument; exit
206 elif [[ "$4" = "" ]]
207 then
208    printf " +++ 4. argument missing \n"
209    locat=argument; exit
210 fi
211
212
213    # USER-NAME AUF ZIELRECHNER AUS .NETRC-DATEI ERMITTELN
214 if [[ -z $remote_user ]]
215 then
216
217       # PRUEFEN, OB NETRC-DATEI VORHANDEN
218    if [[ ! -f ~/.netrc ]]
219    then
220       printf " +++ option -u not given; \n"
221       printf "     getting remote-username from password file failed \n"
222       printf "     because ~/.netrc does not exist \n"
223       locat=netrc; exit
224    fi
225    grep  $1  ~/.netrc | read dum dum dum remote_user dum dum
226 fi
227
228
229    # APPEND IST NUR BEI TRANSFER EINZELNER DATEIEN OHNE UEBERSCHREIBEN
230    # ERLAUBT. GET IST DABEI EBENFALLS NICHT ERLAUBT
231 if [[ $append = true  &&  ( $get = true || $catalog_copy = true || $overwrite = true ) ]]
232 then
233    printf " +++ options -g, -c and -o are not allowed, if -A is given \n"
234    locat=parameter; exit
235 fi
236
237
238    # QUOTE WAIT FUNKTIONIERT NICHT BEIM KOPIEREN GANZER VERZEICHNISSE
239 if [[ $quote_wait = true  &&  $catalog_copy = true ]]
240 then
241    printf " +++ options  -c  and  -q  must not be used simultaneously\n"
242    locat=parameter; exit
243 fi
244
245
246    # IM CHECK-MODUS WIRD SCRIPT HIER BEENDET
247 [[ $check = true ]]  &&  exit
248
249
250    # BESTIMMTE ZEIT WARTEN, BIS WEITERGEMACHT WIRD (NOETIG Z.B. BEI TRANSFER
251    # VON JOBPROTOKOLLEN AUS JOBS HERAUS)
252 sleep  $wait
253
254
255    # Set port number option for calls of ssh/scp, subjob and batch_scp scripts
256 if [[ "$scp_port" != "" ]]
257 then
258    PORTOPT="-P $scp_port"
259    SSH_PORTOPT="-p $scp_port"
260 fi
261
262
263   # Using absolute paths for ssh on lcflow (nodes "cfd_*") as the paths of the
264   # job scheduler have changed
265 if [[ $(echo $local_host | cut -c1-3) = "cfd" ]]
266 then
267   SSH_BIN=/usr/bin/ssh
268 else
269   SSH_BIN=ssh
270 fi
271
272
273    # PRUEFEN, OB LOKALE DATEI/LOKALES VERZEICHNIS VORHANDEN BZW. NICHT VORHANDEN
274 if [[ $get = false ]]
275 then
276    if [[ $catalog_copy = false ]]
277    then
278       if [[ ! -f $2 ]]
279       then
280          printf " +++ file \"$2\" to be transferred does not exist \n"
281          locat=localfile; exit
282       fi
283    else
284       if [[ ! -d $2 ]]
285       then
286          printf " +++ directory \"$2\" to be transferred does not exist\n"
287          printf "     or is not a directory \n"
288          locat=localfile; exit
289       fi
290    fi
291 else
292    if [[ $catalog_copy = false ]]
293    then
294       if [[ -f $2 ]]
295       then
296          if [[ $overwrite = true ]]
297          then
298             rm  $2
299          else
300             printf " +++ local file \"$2\" is already existing \n"
301             locat=localfile; exit
302          fi
303       else
304
305             # PRUEFEN, OB SICH LOKALE DATEI ANLEGEN LAESST
306          local_dirname=`dirname $2`
307          if [[ ! -d $local_dirname ]]
308          then
309             printf " +++ local directory \"$local_dirname\" \n"
310             printf "     does not exist or is not a directory \n"
311             printf " +++ cannot copy file \"$3/$4\" \n"
312             printf "     from \"$1\" to \"$local_host\" \n"
313             locat=localfile; exit
314          fi
315       fi
316    else
317       if [[ -d $2  ||  -f $2 ]]
318       then
319          printf " +++ local directory \"$2\" is already existing, \n"
320          printf "     or a file with the same name exists \n"
321          locat=localfile; exit
322       fi
323    fi
324 fi
325
326
327    # VERZEICHNISLSTE DES ZIELRECHNERS ERSTELLEN
328 if [[ $(echo $local_host | cut -c1-4) = gaia ]]
329 then
330    ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"unset LANG; cd $3; ls -1; echo '*** list complete'\" "  > $filelist  2>&1
331 else
332    $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "unset LANG; cd $3; ls -1; echo '*** list complete'" > $filelist  2>&1
333 fi
334 ssh_status=$?
335
336 if [[ $ssh_status != 0 ]]
337 then
338    if [[ ! -f $filelist ]]
339    then
340       echo " local_host = $local_host   ssh_status = $ssh_status"
341       locat=ssh_failed_1; exit
342    else
343       if [[ $(grep -c "*** list complete" $filelist) = 0 ]]
344       then
345          echo " local_host = $local_host   ssh_status = $ssh_status"
346          locat=ssh_failed_2; exit
347       fi
348    fi
349 fi
350
351
352    # PRUEFEN, OB VERZEICHNIS VORHANDEN IST. WENN GANZES VERZEICHNISS ZUM
353    # ZIELRECHNER KOPIERT WERDEN SOLL, DARF DORT NOCH KEIN ENTSPRECHENDES
354    # VERZEICHNIS VORHANDEN SEIN
355 if [[ $(cat $filelist | grep -c "not found") != 0  || \
356       $(cat $filelist | grep -c "No such file or directory") != 0 ]]
357 then
358    if [[ ! ( $catalog_copy = true  &&  $get = false ) ]]
359    then
360       if [[ $make_catalog = false ]]
361       then
362          printf " +++ directory \"$3\" does not exist on destination host (\"$1\") \n"
363          locat=directory; exit
364       else
365          if [[ $silent = false ]]
366          then
367             printf "  >>> directory \"$3\" does not exist on destination host (\"$1\")"
368             printf "\n      trying to create \"$3\" \n"
369          fi
370
371          make_catalog=force
372       fi
373    fi
374 fi
375
376
377    # PRUEFEN, OB DATEI/VERZEICHNIS VORHANDEN, WENN JA, HOECHSTEN ZYKLUS
378    # ERMITTELN (BZW. IM ABSOLUT-MODUS PRUEFEN, OB DATEI VORHANDEN IST)
379    # DAS GANZE ABER NUR, WENN NICHT OVERWRITE-MODUS GEWAEHLT WURDE, DIE
380    # EVENTUELL VORHANDENE DATEI ALSO UEBERSCHRIEBEN WERDEN SOLL
381 found=false
382 if [[ ( $overwrite = false   &&  $get = false )  ||  $get = true ]]
383 then
384    while  read zeile
385    do
386       if [[ $absolut = false ]]
387       then
388             # REMOVE EXTENSION, IF EXISTING AND GIVEN AS ARGUMENT
389          if [[ "$5" != ""  &&  "$5" != " " ]]
390          then
391             extension=${zeile##*.}
392             if [[ $extension = $5 ]]
393             then
394                text=${zeile%.*}
395             else
396                text=${zeile}
397             fi
398          else
399             text=${zeile}
400          fi
401
402             # GET AND REMOVE CYCLE NUMBER, IF EXISTING, AND CHECK, IF FILE EXISTS
403          cycle=${text##*.}
404          if [[ $cycle = $text ]]
405          then
406                # filename contains no dot, i.e. no cycle number
407             if [[ "$text" = "$4" ]]
408             then
409                found=true
410                (( icycle = 0 ))
411             fi
412          else
413                # filename contains at least one dot
414                # find out if the string after the last dot is a number
415             if [[ $cycle =~ ^-?[0-9]+$ ]]
416             then
417                text=${text%.*}
418                if [[ "$text" = "$4" ]]
419                then
420                   found=true
421                   (( icycle = $cycle ))
422                fi
423             else
424                if [[ "$text" = "$4" ]]
425                then
426                   found=true
427                   (( icycle = 0 ))
428                fi
429             fi
430          fi
431
432
433#          text=$(echo $zeile | cut -f1 -d".")
434#
435#          if [[ "$text" = "$4" ]]
436#          then
437#             found=true
438#             cycle=$(echo $zeile | cut -f2 -d".")
439#             if [[ "$cycle" = "$text" ]]
440#             then
441#                (( icycle = 0 ))
442#             else
443#
444#                   # PRUEFEN, OB CYCLE EINE ZAHL IST
445#                (( iii = 1 ))
446#                character=`echo $cycle | cut -c$iii`
447#                character_found=false
448#                while [[ "$character" != ""  &&  $character_found = false ]]
449#                do
450#                   case  $character  in
451#                      (0|1|2|3|4|5|6|7|8|9)  true;;
452#                      (*)  character_found=true
453#                   esac
454#                   (( iii = iii + 1 ))
455#                   character=`echo $cycle | cut -c$iii`
456#                done
457#
458#                if [[ $character_found = false ]]
459#                then
460#                   (( icycle = $cycle ))
461#                fi
462#             fi >|$errfile 2>&1    # AUSGABE FEHLER AUF ERRFILE WENN CYCLE NICHTNUMERISCH
463#
464#
465#                # INFORMATIVE AUSGABE, WENN DATEI NICHTNUMERISCHE EXTENSION HAT
466#                # if [[ $(cat $errfile | grep -c "bad number") != 0 ]]
467#             if [[ $character_found = true ]]
468#             then
469#                if [[ $cycle != "$5" ]]
470#                then
471#                   printf "  +++ file \"$text\" has non-numerical extension \".$cycle\" \n"
472#                   locat=file; exit
473#                else
474#                   if [[ $silent = false ]]
475#                   then
476#                      printf "  >>> file \"$text\" has non-numerical extension \".$cycle\" \n"
477#                   fi
478#                fi
479#             fi
480
481             if (( icycle > maxcycle ))
482             then
483                (( maxcycle = icycle ))
484             fi
485#          fi
486
487       else
488
489             # IM ABSOLUT-MODUS MUSS NUR GEPRUEFT WERDEN, OB DIE DATEI
490             # VORHANDEN IST
491          [[ $4 = $zeile ]]  &&  found=true
492       fi
493
494    done <$filelist
495 fi
496
497 if [[ $found = true ]]
498 then
499    if [[ $get = false ]]
500    then
501       if [[ $absolut = false ]]
502       then
503          if [[ $append = false ]]
504          then
505             (( maxcycle = maxcycle + 1 ))
506                # TRY TO USE FIXED CYCLE NUMBER, IF GIVEN AS OPTION
507             if [[ "$usecycle" != "" ]]
508             then
509                if (( usecycle >= maxcycle ))
510                then
511                   (( maxcycle = usecycle ))
512                else
513                    printf "  >>> Unfied cycle number cannot be used\n"
514                fi
515             fi
516             zyklusnr=".$maxcycle"
517          else
518             if (( maxcycle == 0 ))
519             then
520                zyklusnr=""
521             else
522                zyklusnr=".$maxcycle"
523             fi
524          fi
525       else
526          if [[ $overwrite = false ]]
527          then
528             printf "  +++ file \"$3/$4\" \n"
529             printf "      already exists on destination host (use -o, if necessary) \n"
530             locat=file; exit
531          fi
532       fi
533    else
534       if [[ $absolut = false ]]
535       then
536          if (( maxcycle == 0 ))
537          then
538             zyklusnr=""
539          else
540             zyklusnr=".$maxcycle"
541             (( maxcycle = 0 ))
542          fi
543       else
544          zyklusnr=""
545       fi
546    fi
547
548 else
549
550    if [[ "$usecycle" != "" ]]
551    then
552       (( maxcycle = usecycle ))
553       zyklusnr=".$usecycle"
554    else
555       zyklusnr=""
556    fi
557
558       # ABBRUCH, WENN DATEI VON ZIELRECHNER GEHOLT WERDEN SOLL, DORT ABER
559       # NICHT VORHANDEN IST
560    if [[ $get = true ]]
561    then
562       printf " +++ file \"$3/$4\" \n"
563       printf "     does not exist on destination host (\"$1\") \n"
564       locat=remotefile; exit
565    fi
566 fi
567
568
569    # FALLS KATALOG ERZEUGT WIRD, DARF DIE DATEI IN KEINEM FALL EINE
570    # ZYKLUSNUMMER BESITZEN, DA SIE JA NOCh GARNICHT EXISTIEREN KANN
571 if [[ $make_catalog = force ]]
572 then
573    zyklusnr=""
574    (( maxcycle = 0 ))
575 fi
576
577 
578    # FALLS NAMENSOPTION (-n) GEWAEHLT WURDE, NUR DEN ERMITTELTEN LOKALEN
579    # DATEINAMEN DES ZIELRECHNERS AUSGEBEN UND SCRIPT BEENDEN
580 if [[ $print_local_filename = true ]]
581 then
582    printf "$4$zyklusnr\n"
583    rm -r $filelist
584    exit
585 fi
586
587
588    # FALLS 5. ARGUMENT ANGEGEBEN WURDE, WIRD DIES ALS FILE-EXTENSION
589    # HINTER DIE ZYKLUS-NUMMER GEHAENGT (FUNKTIONIERT NUR BEI KOPIEREN EINER
590    # DATEI AUF ZIELRECHNER
591 if [[ "$5" != ""  &&  $get = false ]]
592 then
593    zyklusnr=${zyklusnr}.$5
594 fi
595
596
597    # BEI VERZEICHNISTRANSFER VON ZIELRECHNER AUF LOKALEN RECHNER PRUEFEN, OB
598    # $3 AUF ZIELRECHNER WIRKLICH EIN VERZEICHNIS IST
599 if [[ $catalog_copy = true  &&  $get = true ]]
600 then
601    rm -rf $filelist
602    if [[ $(echo $local_host | cut -c1-4) = gaia ]]
603    then
604       ssh $SSH_PORTOPT $local_user@gaiad "ssh $1 -l $remote_user \"cd $3\" " > $filelist
605    else
606       $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "cd $3" > $filelist
607    fi
608    if [[ $? != 0 ]]
609    then
610       locat=ssh_failed_3; exit
611    fi
612
613    if [[ $(cat $filelist | grep -c "Not a directory") != 0 ]]
614    then
615       printf " +++ \"$3\" on destination host is not a directory \n"
616       locat=directory; exit
617    fi
618 fi
619
620
621    # BEI KATALOGTRANSFER AUF LOKALEN RECHNER ENTSPRECHENDES VERZEICHNIS
622    # ANLEGEN
623 if [[ $catalog_copy = true ]]
624 then
625    if [[ $get = true ]]
626    then
627       mkdir $2
628    fi
629 fi
630
631
632    # Auf IBM-Rechnern (HLRN) Tilde aus Katalognamen entfernen, da scp
633    # diese nicht versteht
634 catalog_name=$3
635 if [[ $(hostname | cut -c1-4) = hreg  ||  $(hostname | cut -c1-4) = breg ]]
636 then
637    catalog_name=${catalog_name#"~/"}
638    catalog_name=${catalog_name#"~"}
639 fi
640 [[ "$catalog_name" != "" ]]  &&  catalog_name=${catalog_name}/
641
642
643    # DATEI/VERZEICHNIS PER SCP UEBERTRAGEN
644 if [[ $get = false ]]
645 then
646    if [[ $make_catalog != force ]]
647    then
648       if [[ $append = false ]]
649       then
650          if [[ $(echo $local_host | cut -c1-2) = cs ]]
651          then
652             if [[ $catalog_copy = false ]]
653             then
654                scp $PORTOPT -p -q -v $2 $remote_user@$1:$catalog_name$4$zyklusnr
655             else
656                scp $PORTOPT -p -r -q -v $2 $remote_user@$1:$catalog_name$4$zyklusnr
657             fi
658          elif [[ $(echo $local_host | cut -c1-4) = gaia ]]
659          then
660             if [[ $catalog_copy = false ]]
661             then
662                ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
663             else
664                ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
665             fi
666          else
667             if [[ $catalog_copy = false ]]
668             then
669                scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
670             else
671                scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
672             fi
673          fi
674          scp_status=$?
675
676          if [[ $scp_status != 0 ]]
677          then
678                # CHECK, OB DATEIGROESSEN AUF LOKALEM UND REMOTERECHNER
679                # UEBEREINSTIMMEN
680             local_size=`ls -al  $2`
681             local_size=`echo $local_size | cut -d" " -f5`
682
683             if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
684             then
685                remote_size=`ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"ls -al $catalog_name$4$zyklusnr\" "`
686             else
687                remote_size=`$SSH_BIN $SSH_PORTOPT $1 -l $remote_user "ls -al $catalog_name$4$zyklusnr"`
688             fi
689             remote_size=`echo $remote_size | cut -d" " -f5`
690
691             if [[ "$remote_size" != "$local_size" ]]
692             then
693                echo " +++ scp failed on host \"$local_host\" with exit $scp_status"
694                echo "     local size = \"$local_size\"  remote size = \"$remote_size\" "
695                date
696                locat=scp_failed; exit
697             fi
698          fi
699       else
700          if [[ $(echo $local_host | cut -c1-4) = gaia ]]
701          then
702             ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random"  > /dev/null
703          else
704             scp $PORTOPT -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random  > /dev/null
705          fi
706          if [[ $? != 0 ]]
707          then
708                # CHECK, OB DATEIGROESSEN AUF LOKALEM UND REMOTERECHNER
709                # UEBEREINSTIMMEN
710             local_size=`ls -al  $2`
711             local_size=`echo $local_size | cut -d" " -f5`
712
713             if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
714             then
715                remote_size=`ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"ls -al ${catalog_name}batch_scp_append_file.$random\" "`
716             else
717                remote_size=`$SSH_BIN $SSH_PORTOPT $1 -l $remote_user "ls -al ${catalog_name}batch_scp_append_file.$random"`
718             fi
719             remote_size=`echo $remote_size | cut -d" " -f5`
720
721             if [[ "$remote_size" != "$local_size" ]]
722             then
723                echo " +++ scp failed on host \"$local_host\" with exit $scp_status"
724                echo "     local size = \"$local_size\"  remote size = \"$remote_size\" "
725                date
726                locat=scp_for_append_failed; exit
727             fi
728          fi
729
730          rm  $filelist
731
732          if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
733          then
734             ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"cd $3; cat batch_scp_append_file.$random >> $4$zyklusnr; rm batch_scp_append_file.$random; echo '*** append complete'\" " > $filelist
735          else
736             $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "cd $3; cat batch_scp_append_file.$random >> $4$zyklusnr; rm batch_scp_append_file.$random; echo '*** append complete'" > $filelist
737          fi
738          if [[ $? != 0 ]]
739          then
740             if [[ ! -f $filelist ]]
741             then
742                locat=append_via_ssh_failed; exit
743             else
744                if [[ $(grep -c "*** append complete" $filelist) = 0 ]]
745                then
746                   locat=append_via_ssh_failed; exit
747                fi
748             fi
749          fi
750       fi
751    else
752       if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
753       then
754          ssh $SSH_PORTOPT $local_user@gaiad "ssh $1 -l $remote_user \"mkdir -p $3\" "
755       else
756          $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "mkdir -p $3"
757       fi
758       if [[ $? != 0 ]]
759       then
760          locat=ssh_failed_4; exit
761       fi
762       if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
763       then
764          ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
765       else
766          scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
767       fi
768       if [[ $? != 0 ]]
769       then
770          locat=scp_failed; exit
771       fi
772    fi
773
774 else
775
776    if [[ $catalog_copy = false ]]
777    then
778       if [[ $quote_wait = true ]]
779       then
780
781          printf " +++ quote wait not realized with BATCH_SCP"
782          locat=unavailable_feature; exit
783
784       else
785
786          if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
787          then
788             ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $remote_user@$1:$catalog_name$4$zyklusnr $2"  > /dev/null
789          else
790             scp $PORTOPT -p $remote_user@$1:$catalog_name$4$zyklusnr $2  > /dev/null
791          fi
792          if [[ $? != 0 ]]
793          then
794             locat=scp_failed; exit
795          fi
796
797       fi
798    else
799
800       printf " +++ get of whole cataloges not realized with BATCH_SCP so far"
801       locat=unavailable_feature; exit
802
803#       ftp -i $1 << %END%  > /dev/null
804#$transfermode
805#cd $3
806#mget *
807#quit
808#%END%
809    fi
810 fi
811
812
813
814    # EVTL. TRANSFERIERTE DATEI AUF LOKALEM RECHNER LOESCHEN
815 if [[ $delete = true  &&  $get = false ]]
816 then
817    rm -rf  $2
818 fi
819
820
821
822    # ABSCHLUSSMELDUNG
823 if [[ $silent = false ]]
824 then
825    if (( maxcycle == 0 ))
826    then
827       if [[ $append = false ]]
828       then
829          printf "  >>> transfer successful \n"
830       else
831          printf "  >>> file was appended \n"
832       fi
833    else
834       printf "  >>> transfer successful \n"
835       if [[ $append = false ]]
836       then
837          if [[ $catalog_copy = false ]]
838          then
839             printf "      new file has cycle number $maxcycle \n"
840          else
841             printf "      new catalog has cycle number $maxcycle \n"
842          fi
843       else
844          printf "      append to cycle number $maxcycle \n"
845       fi
846    fi
847 fi
848
849 rm -rf  $filelist  $errfile
Note: See TracBrowser for help on using the repository browser.