source: palm/trunk/SCRIPTS/batch_scp @ 1094

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

scp/ssh port can be set explicitly

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