source: palm/trunk/SCRIPTS/batch_scp @ 1099

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

adjustments for Forwind cluster (lcflow) and Kuyshu University computing center (hayaka -lckyuh); further small adjustments for lckyut

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