source: palm/trunk/SCRIPTS/batch_scp @ 1202

Last change on this file since 1202 was 1202, checked in by witha, 11 years ago

script adjustments for Forwind cluster (lcflow)

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