source: palm/trunk/SCRIPTS/batch_scp @ 1319

Last change on this file since 1319 was 1310, checked in by raasch, 11 years ago

update of GPL copyright

  • Property svn:keywords set to Id
File size: 24.7 KB
RevLine 
[1]1#! /bin/ksh
2
[1090]3# batch_scp - script for automatic file/directory transfer using scp
[1]4
[1090]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#
[1310]19# Copyright 1997-2014  Leibniz Universitaet Hannover
[1090]20#--------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
24#
[1203]25#
[1090]26# Former revisions:
27# -----------------
28# $Id: batch_scp 1310 2014-03-14 08:01:56Z raasch $
29#
[1203]30# 1202 2013-07-10 16:22:07Z witha
31# adjustments for Forwind cluster (lcflow): using absolute paths for ssh
32#
[1100]33# 1099 2013-02-10 01:47:43Z raasch
34# LANG variable is unset in some ssh calls to guarantee messages in English
35#
[1096]36# 1094 2013-02-03 01:52:12Z raasch
37# new option -P for explicit setting of ssh/scp port
38#
[1091]39# 1090 2013-02-02 07:06:13Z raasch
40# code put under GPL (PALM 3.9)
41# adjustments for Kyushu-University computing center (lckyut)
42# old changelog messages removed
43#
[1090]44# 08/03/11 - Siggi - adjustments for ibmkisti: this machine allows
45#                    outgoing ssh/scp connections only from the
46#                    interactive nodes (gaiad). All ssh/scp traffic is
47#                    done via this interactive node.
48# 04/01/02 - Siggi - first version finished
49# 29/11/01 - Siggi - script development started
50#
51#--------------------------------------------------------------------------------#
52# batch_scp - script for automatic file/directory transfers using scp
53#
54# batch_scp has 4 arguments:
55#               $1 = IP-addres of remote (target) machine
56#               $2 = file to be transferred
57#               $3 = directory of remote machine, where file should be copied to
58#               $4 = filename that file should be given on remote machine
59#
60# ATTENTION: problems might occur if directories on remote machine include very
61#            old files for which "ls -al" does give "year" as modification
62#            time instead of "hh:mm". In such a case, batch_scp cannot check the
63#            filename and may not find the file (e.g. if option -g is used).
64#--------------------------------------------------------------------------------#
[1]65
66
67 
68    # VARIABLENVEREINBARUNGEN + DEFAULTWERTE
69 random=$RANDOM
70
71 absolut=false
72 append=false
73 catalog_copy=false
74 check=false
75 delete=false
[1090]76 errfile=batch_scp.errfile.$random
[1]77 filelist=filelist.$random
78 get=false
79 local_host=`hostname`
[693]80 local_user=$USER
81 local_wdir=`pwd`
[1]82 locat=normal
83 make_catalog=false
84 overwrite=false
85 print_local_filename=false
86 quote_wait=false
87 remote_user=""
88 silent=false
89 transfermode=binary
90 zyklusnr=""
91 typeset -i iii icycle maxcycle=0 wait=0
92
93    # FEHLERBEHANDLUNG
94    # BEI EXIT:
95 trap 'if [[ $locat != normal ]]
96       then
[1090]97          [[ -f "$filelist" ]]  &&  cat $filelist
98          [[ -f "$errfile"  ]]  &&  cat $errfile
[1]99          rm -rf $filelist $errfile
100          printf " +++ BATCH_SCP terminated \n"
101          printf "     locat     = $locat \n"
102          printf "     arguments = $1 $2 $3 $4 \n\n"
103          exit 1
104       fi' exit
105
106
107    # BEI TERMINAL-BREAK:
108 trap 'rm -rf $filelist $errfile
109       printf " +++ BATCH_SCP terminated \n\n"
110       exit 1
111      ' 2
112
113
114    # SHELLSCRIPT-OPTIONEN EINLESEN
[1094]115 while  getopts  :aAbcCdgmnoP:qsu:w:  option
[1]116 do
117   case  $option  in
118       (a)   absolut=true;;
119       (A)   append=true;;
120       (b)   transfermode=binary;;
121       (c)   catalog_copy=true;;
122       (C)   check=true;;
123       (d)   delete=true;;
124       (g)   get=true;;
125       (m)   make_catalog=true;;
126       (n)   print_local_filename=true;;  # Option ist nicht dokumentiert !
127       (o)   overwrite=true;;
[1094]128       (P)   scp_port=$OPTARG;;
[1]129       (q)   quote_wait=true;;
130       (s)   silent=true;;
131       (u)   remote_user=$OPTARG;;
132       (w)   wait=$OPTARG;;
133       (\?)  printf "  +++ option $OPTARG unknown \n"
134             printf "  --> call: batch_scp [-aAbcCdgmnoqsuw] <IP-adress> <localfile> <remotepath> <remotefile>\n"
135             locat=parameter;exit;;
136   esac
137 done
138 shift OPTIND-1
139
140
141 
142    # KURZE AUFRUFBESCHREIBUNG WIRD HIER AUSGEGEBEN
143 if [ "$1" = "?" ]
144 then
145   (printf "\n  *** batch_scp can be called as follows:\n"
146    printf "\n      batch_scp -a -b -d -g -o -q -s -u.. -w..  <param1> <param2> <param3> <param4>\n"
147    printf "\n      Description of available options:\n"
148    printf "\n      Option  Description                            Default-Value"
149    printf "\n        -a    Filenames are absolute. No cycle-      ---"
150    printf "\n              numbers will be determined"
151    printf "\n        -A    append to destination file             ---"
152    printf "\n        -b    use binary-modus for transfer          ASCII-modus"
153    printf "\n        -c    transfer of directory                  ---"
154    printf "\n        -C    check-Modus, no transfer               ---"
155    printf "\n        -d    file to be transferred will be         ---"
156    printf "\n              deleted after successful transfer"
157    printf "\n        -g    change of transfer direction, i.e.     ---"
158    printf "\n              file will be transferred from"
159    printf "\n              destination host"
160    printf "\n        -o    any existing file will be overwritten  ---"
161    printf "\n        -q    switch on  \"quote wait\"  on          ---"
162    printf "\n              estination host"
163    printf "\n        -s    do not display informative messages    ---"
164    printf "\n        -u    username on remote machine             <username>"
165    printf "\n        -w    waiting time in seconds, before trans- 0"
166    printf "\n              fer will be initiated"
167    printf "\n "
168    printf "\n      The positional parameters <param1> - <param4> must be provided at"
169    printf "\n      any time and have the following meaning:"
170    printf "\n        <param1>  -  IP-adress of destination host"
171    printf "\n                     or \"?\"  (creates this outline)"
172    printf "\n        <param2>  -  abs. or rel. path of file to be transferred"
173    printf "\n        <param3>  -  directory (abs.!) on destination host. Special cahracters"
174    printf "\n                     like \~ are allowed but must be quoted by \"."
175    printf "\n        <param4>  -  filename (without path!) on destination host; must not"
176    printf "\n                     be given, if option -c is used."
177    printf "\n      When using option -g, file will be copied from destination host to file"
178    printf "\n      <param2>. In this case, no overwriting is possible.") | more
179    exit
180 fi
181
182
183    # PRUEFEN, OB ALLE ARGUMENTE VORLIEGEN
184 if [[ "$1" = "" ]]
185 then
186    printf " +++ 1. argument missing \n"
187    locat=argument; exit
188 elif [[ "$2" = "" ]]
189 then
190    printf " +++ 2. argument missing \n"
191    locat=argument; exit
192 elif [[ "$3" = "" ]]
193 then
194    printf " +++ 3. argument missing \n"
195    locat=argument; exit
196 elif [[ "$4" = "" ]]
197 then
198    printf " +++ 4. argument missing \n"
199    locat=argument; exit
200 fi
201
202
203    # USER-NAME AUF ZIELRECHNER AUS .NETRC-DATEI ERMITTELN
204 if [[ -z $remote_user ]]
205 then
206
207       # PRUEFEN, OB NETRC-DATEI VORHANDEN
208    if [[ ! -f ~/.netrc ]]
209    then
210       printf " +++ option -u not given; \n"
211       printf "     getting remote-username from password file failed \n"
212       printf "     because ~/.netrc does not exist \n"
213       locat=netrc; exit
214    fi
215    grep  $1  ~/.netrc | read dum dum dum remote_user dum dum
216 fi
217
218
219    # APPEND IST NUR BEI TRANSFER EINZELNER DATEIEN OHNE UEBERSCHREIBEN
220    # ERLAUBT. GET IST DABEI EBENFALLS NICHT ERLAUBT
221 if [[ $append = true  &&  ( $get = true || $catalog_copy = true || $overwrite = true ) ]]
222 then
223    printf " +++ options -g, -c and -o are not allowed, if -A is given \n"
224    locat=parameter; exit
225 fi
226
227
228    # DATEINAME IM 4. ARGUMENT DARF NUR BEIM UEBERSCHREIBEN ODER IM ABSOLUT-
229    # MODUS PUNKTE ENTHALTEN
230 if [[ $overwrite = false  &&  $absolut = false  &&  $(echo $4 | grep -c "\.") != 0 ]]
231 then
232    printf " +++ 4th argument may only contain dots (".") , if one of the \n"
233    printf "     options -a or -o are given \n"
234    locat=argument; 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
[1094]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
[1202]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
[1]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
[693]328 if [[ $(echo $local_host | cut -c1-4) = gaia ]]
329 then
[1099]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
[693]331 else
[1202]332    $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "unset LANG; cd $3; ls -1; echo '*** list complete'" > $filelist  2>&1
[693]333 fi
[1]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          text=$(echo $zeile | cut -f1 -d".")
389          if [[ "$text" = "$4" ]]
390          then
391             found=true
392             cycle=$(echo $zeile | cut -f2 -d".")
393             if [[ "$cycle" = "$text" ]]
394             then
395                (( icycle = 0 ))
396             else
397
398                   # PRUEFEN, OB CYCLE EINE ZAHL IST
399                (( iii = 1 ))
400                character=`echo $cycle | cut -c$iii`
401                character_found=false
402                while [[ "$character" != ""  &&  $character_found = false ]]
403                do
404                   case  $character  in
405                      (0|1|2|3|4|5|6|7|8|9)  true;;
406                      (*)  character_found=true
407                   esac
408                   (( iii = iii + 1 ))
409                   character=`echo $cycle | cut -c$iii`
410                done
411
412                if [[ $character_found = false ]]
413                then
414                   (( icycle = $cycle ))
415                fi
416             fi >|$errfile 2>&1    # AUSGABE FEHLER AUF ERRFILE WENN CYCLE NICHTNUMERISCH
417
418
419                # INFORMATIVE AUSGABE, WENN DATEI NICHTNUMERISCHE EXTENSION HAT
420                # if [[ $(cat $errfile | grep -c "bad number") != 0 ]]
421             if [[ $character_found = true ]]
422             then
423                if [[ $cycle != "$5" ]]
424                then
425                   printf "  +++ file \"$text\" has non-numerical extension \".$cycle\" \n"
426                   locat=file; exit
427                else
428                   if [[ $silent = false ]]
429                   then
430                      printf "  >>> file \"$text\" has non-numerical extension \".$cycle\" \n"
431                   fi
432                fi
433             fi
434
435             if (( icycle > maxcycle ))
436             then
437                (( maxcycle = icycle ))
438             fi
439          fi
440
441       else
442
443             # IM ABSOLUT-MODUS MUSS NUR GEPRUEFT WERDEN, OB DIE DATEI
444             # VORHANDEN IST
445          [[ $4 = $zeile ]]  &&  found=true
446       fi
447
448    done <$filelist
449 fi
450
451 if [[ $found = true ]]
452 then
453    if [[ $get = false ]]
454    then
455       if [[ $absolut = false ]]
456       then
457          if [[ $append = false ]]
458          then
459             (( maxcycle = maxcycle + 1 ))
460             zyklusnr=".$maxcycle"
461          else
462             if (( maxcycle == 0 ))
463             then
464                zyklusnr=""
465             else
466                zyklusnr=".$maxcycle"
467             fi
468          fi
469       else
470          if [[ $overwrite = false ]]
471          then
472             printf "  +++ file \"$3/$4\" \n"
473             printf "      already exists on destination host (use -o, if necessary) \n"
474             locat=file; exit
475          fi
476       fi
477    else
478       if [[ $absolut = false ]]
479       then
480          if (( maxcycle == 0 ))
481          then
482             zyklusnr=""
483          else
484             zyklusnr=".$maxcycle"
485             (( maxcycle = 0 ))
486          fi
487       else
488          zyklusnr=""
489       fi
490    fi
491 else
492    zyklusnr=""
493
494       # ABBRUCH, WENN DATEI VON ZIELRECHNER GEHOLT WERDEN SOLL, DORT ABER
495       # NICHT VORHANDEN IST
496    if [[ $get = true ]]
497    then
498       printf " +++ file \"$3/$4\" \n"
499       printf "     does not exist on destination host (\"$1\") \n"
500       locat=remotefile; exit
501    fi
502 fi
503
504
505    # FALLS KATALOG ERZEUGT WIRD, DARF DIE DATEI IN KEINEM FALL EINE
506    # ZYKLUSNUMMER BESITZEN, DA SIE JA NOCh GARNICHT EXISTIEREN KANN
507 if [[ $make_catalog = force ]]
508 then
509    zyklusnr=""
510    (( maxcycle = 0 ))
511 fi
512
513 
514    # FALLS NAMENSOPTION (-n) GEWAEHLT WURDE, NUR DEN ERMITTELTEN LOKALEN
515    # DATEINAMEN DES ZIELRECHNERS AUSGEBEN UND SCRIPT BEENDEN
516 if [[ $print_local_filename = true ]]
517 then
518    printf "$4$zyklusnr\n"
519    rm -r $filelist
520    exit
521 fi
522
523
524    # FALLS 5. ARGUMENT ANGEGEBEN WURDE, WIRD DIES ALS FILE-EXTENSION
525    # HINTER DIE ZYKLUS-NUMMER GEHAENGT (FUNKTIONIERT NUR BEI KOPIEREN EINER
526    # DATEI AUF ZIELRECHNER
527 if [[ "$5" != ""  &&  $get = false ]]
528 then
529    zyklusnr=${zyklusnr}.$5
530 fi
531
532
533    # BEI VERZEICHNISTRANSFER VON ZIELRECHNER AUF LOKALEN RECHNER PRUEFEN, OB
534    # $3 AUF ZIELRECHNER WIRKLICH EIN VERZEICHNIS IST
535 if [[ $catalog_copy = true  &&  $get = true ]]
536 then
537    rm -rf $filelist
[693]538    if [[ $(echo $local_host | cut -c1-4) = gaia ]]
539    then
[1094]540       ssh $SSH_PORTOPT $local_user@gaiad "ssh $1 -l $remote_user \"cd $3\" " > $filelist
[693]541    else
[1202]542       $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "cd $3" > $filelist
[693]543    fi
[1]544    if [[ $? != 0 ]]
545    then
546       locat=ssh_failed_3; exit
547    fi
548
549    if [[ $(cat $filelist | grep -c "Not a directory") != 0 ]]
550    then
551       printf " +++ \"$3\" on destination host is not a directory \n"
552       locat=directory; exit
553    fi
554 fi
555
556
557    # BEI KATALOGTRANSFER AUF LOKALEN RECHNER ENTSPRECHENDES VERZEICHNIS
558    # ANLEGEN
559 if [[ $catalog_copy = true ]]
560 then
561    if [[ $get = true ]]
562    then
563       mkdir $2
564    fi
565 fi
566
567
568    # Auf IBM-Rechnern (HLRN) Tilde aus Katalognamen entfernen, da scp
569    # diese nicht versteht
570 catalog_name=$3
571 if [[ $(hostname | cut -c1-4) = hreg  ||  $(hostname | cut -c1-4) = breg ]]
572 then
573    catalog_name=${catalog_name#"~/"}
574    catalog_name=${catalog_name#"~"}
575 fi
576 [[ "$catalog_name" != "" ]]  &&  catalog_name=${catalog_name}/
577
578
579    # DATEI/VERZEICHNIS PER SCP UEBERTRAGEN
580 if [[ $get = false ]]
581 then
582    if [[ $make_catalog != force ]]
583    then
584       if [[ $append = false ]]
585       then
586          if [[ $(echo $local_host | cut -c1-2) = cs ]]
587          then
588             if [[ $catalog_copy = false ]]
589             then
[1094]590                scp $PORTOPT -p -q -v $2 $remote_user@$1:$catalog_name$4$zyklusnr
[1]591             else
[1094]592                scp $PORTOPT -p -r -q -v $2 $remote_user@$1:$catalog_name$4$zyklusnr
[1]593             fi
[693]594          elif [[ $(echo $local_host | cut -c1-4) = gaia ]]
595          then
596             if [[ $catalog_copy = false ]]
597             then
[1094]598                ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
[693]599             else
[1094]600                ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
[693]601             fi
[1]602          else
603             if [[ $catalog_copy = false ]]
604             then
[1094]605                scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
[1]606             else
[1094]607                scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
[1]608             fi
609          fi
610          scp_status=$?
611
612          if [[ $scp_status != 0 ]]
613          then
614                # CHECK, OB DATEIGROESSEN AUF LOKALEM UND REMOTERECHNER
615                # UEBEREINSTIMMEN
616             local_size=`ls -al  $2`
617             local_size=`echo $local_size | cut -d" " -f5`
618
[693]619             if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
620             then
[1094]621                remote_size=`ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"ls -al $catalog_name$4$zyklusnr\" "`
[693]622             else
[1202]623                remote_size=`$SSH_BIN $SSH_PORTOPT $1 -l $remote_user "ls -al $catalog_name$4$zyklusnr"`
[693]624             fi
[1]625             remote_size=`echo $remote_size | cut -d" " -f5`
626
627             if [[ "$remote_size" != "$local_size" ]]
628             then
629                echo " +++ scp failed on host \"$local_host\" with exit $scp_status"
630                echo "     local size = \"$local_size\"  remote size = \"$remote_size\" "
631                date
632                locat=scp_failed; exit
633             fi
634          fi
635       else
[693]636          if [[ $(echo $local_host | cut -c1-4) = gaia ]]
637          then
[1094]638             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
[693]639          else
[1094]640             scp $PORTOPT -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random  > /dev/null
[693]641          fi
[1]642          if [[ $? != 0 ]]
643          then
644                # CHECK, OB DATEIGROESSEN AUF LOKALEM UND REMOTERECHNER
645                # UEBEREINSTIMMEN
646             local_size=`ls -al  $2`
647             local_size=`echo $local_size | cut -d" " -f5`
648
[693]649             if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
650             then
[1094]651                remote_size=`ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"ls -al ${catalog_name}batch_scp_append_file.$random\" "`
[693]652             else
[1202]653                remote_size=`$SSH_BIN $SSH_PORTOPT $1 -l $remote_user "ls -al ${catalog_name}batch_scp_append_file.$random"`
[693]654             fi
[1]655             remote_size=`echo $remote_size | cut -d" " -f5`
656
657             if [[ "$remote_size" != "$local_size" ]]
658             then
659                echo " +++ scp failed on host \"$local_host\" with exit $scp_status"
660                echo "     local size = \"$local_size\"  remote size = \"$remote_size\" "
661                date
662                locat=scp_for_append_failed; exit
663             fi
664          fi
665
666          rm  $filelist
667
[693]668          if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
669          then
[1094]670             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
[693]671          else
[1202]672             $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
[693]673          fi
[1]674          if [[ $? != 0 ]]
675          then
676             if [[ ! -f $filelist ]]
677             then
678                locat=append_via_ssh_failed; exit
679             else
680                if [[ $(grep -c "*** append complete" $filelist) = 0 ]]
681                then
682                   locat=append_via_ssh_failed; exit
683                fi
684             fi
685          fi
686       fi
687    else
[693]688       if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
689       then
[1094]690          ssh $SSH_PORTOPT $local_user@gaiad "ssh $1 -l $remote_user \"mkdir -p $3\" "
[693]691       else
[1202]692          $SSH_BIN $SSH_PORTOPT $1 -l $remote_user "mkdir -p $3"
[693]693       fi
[1]694       if [[ $? != 0 ]]
695       then
696          locat=ssh_failed_4; exit
697       fi
[693]698       if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
699       then
[1094]700          ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
[693]701       else
[1094]702          scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
[693]703       fi
[1]704       if [[ $? != 0 ]]
705       then
706          locat=scp_failed; exit
707       fi
708    fi
709
710 else
711
712    if [[ $catalog_copy = false ]]
713    then
714       if [[ $quote_wait = true ]]
715       then
716
717          printf " +++ quote wait not realized with BATCH_SCP"
718          locat=unavailable_feature; exit
719
720       else
721
[693]722          if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
723          then
[1094]724             ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $remote_user@$1:$catalog_name$4$zyklusnr $2"  > /dev/null
[693]725          else
[1094]726             scp $PORTOPT -p $remote_user@$1:$catalog_name$4$zyklusnr $2  > /dev/null
[693]727          fi
[1]728          if [[ $? != 0 ]]
729          then
730             locat=scp_failed; exit
731          fi
732
733       fi
734    else
735
736       printf " +++ get of whole cataloges not realized with BATCH_SCP so far"
737       locat=unavailable_feature; exit
738
739#       ftp -i $1 << %END%  > /dev/null
740#$transfermode
741#cd $3
742#mget *
743#quit
744#%END%
745    fi
746 fi
747
748
749
750    # EVTL. TRANSFERIERTE DATEI AUF LOKALEM RECHNER LOESCHEN
751 if [[ $delete = true  &&  $get = false ]]
752 then
753    rm -rf  $2
754 fi
755
756
757
758    # ABSCHLUSSMELDUNG
759 if [[ $silent = false ]]
760 then
761    if (( maxcycle == 0 ))
762    then
763       if [[ $append = false ]]
764       then
765          printf "  >>> transfer successful \n"
766       else
767          printf "  >>> file was appended \n"
768       fi
769    else
770       printf "  >>> transfer successful \n"
771       if [[ $append = false ]]
772       then
773          if [[ $catalog_copy = false ]]
774          then
775             printf "      new file has cycle number $maxcycle \n"
776          else
777             printf "      new catalog has cycle number $maxcycle \n"
778          fi
779       else
780          printf "      append to cycle number $maxcycle \n"
781       fi
782    fi
783 fi
784
785 rm -rf  $filelist  $errfile
Note: See TracBrowser for help on using the repository browser.