source: palm/trunk/SCRIPTS/batch_scp @ 1117

Last change on this file since 1117 was 1100, checked in by raasch, 12 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 24.3 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#
19# Copyright 1997-2012  Leibniz University Hannover
20#--------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
[1100]24#
[1090]25#
26# Former revisions:
27# -----------------
28# $Id: batch_scp 1100 2013-02-10 01:58:22Z suehring $
29#
[1100]30# 1099 2013-02-10 01:47:43Z raasch
31# LANG variable is unset in some ssh calls to guarantee messages in English
32#
[1096]33# 1094 2013-02-03 01:52:12Z raasch
34# new option -P for explicit setting of ssh/scp port
35#
[1091]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#
[1090]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#--------------------------------------------------------------------------------#
[1]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
[1090]73 errfile=batch_scp.errfile.$random
[1]74 filelist=filelist.$random
75 get=false
76 local_host=`hostname`
[693]77 local_user=$USER
78 local_wdir=`pwd`
[1]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
[1090]94          [[ -f "$filelist" ]]  &&  cat $filelist
95          [[ -f "$errfile"  ]]  &&  cat $errfile
[1]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
[1094]112 while  getopts  :aAbcCdgmnoP:qsu:w:  option
[1]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;;
[1094]125       (P)   scp_port=$OPTARG;;
[1]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
[1094]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
[1]260    # PRUEFEN, OB LOKALE DATEI/LOKALES VERZEICHNIS VORHANDEN BZW. NICHT VORHANDEN
261 if [[ $get = false ]]
262 then
263    if [[ $catalog_copy = false ]]
264    then
265       if [[ ! -f $2 ]]
266       then
267          printf " +++ file \"$2\" to be transferred does not exist \n"
268          locat=localfile; exit
269       fi
270    else
271       if [[ ! -d $2 ]]
272       then
273          printf " +++ directory \"$2\" to be transferred does not exist\n"
274          printf "     or is not a directory \n"
275          locat=localfile; exit
276       fi
277    fi
278 else
279    if [[ $catalog_copy = false ]]
280    then
281       if [[ -f $2 ]]
282       then
283          if [[ $overwrite = true ]]
284          then
285             rm  $2
286          else
287             printf " +++ local file \"$2\" is already existing \n"
288             locat=localfile; exit
289          fi
290       else
291
292             # PRUEFEN, OB SICH LOKALE DATEI ANLEGEN LAESST
293          local_dirname=`dirname $2`
294          if [[ ! -d $local_dirname ]]
295          then
296             printf " +++ local directory \"$local_dirname\" \n"
297             printf "     does not exist or is not a directory \n"
298             printf " +++ cannot copy file \"$3/$4\" \n"
299             printf "     from \"$1\" to \"$local_host\" \n"
300             locat=localfile; exit
301          fi
302       fi
303    else
304       if [[ -d $2  ||  -f $2 ]]
305       then
306          printf " +++ local directory \"$2\" is already existing, \n"
307          printf "     or a file with the same name exists \n"
308          locat=localfile; exit
309       fi
310    fi
311 fi
312
313
314    # VERZEICHNISLSTE DES ZIELRECHNERS ERSTELLEN
[693]315 if [[ $(echo $local_host | cut -c1-4) = gaia ]]
316 then
[1099]317    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]318 else
[1099]319    ssh $SSH_PORTOPT $1 -l $remote_user "unset LANG; cd $3; ls -1; echo '*** list complete'" > $filelist  2>&1
[693]320 fi
[1]321 ssh_status=$?
322
323 if [[ $ssh_status != 0 ]]
324 then
325    if [[ ! -f $filelist ]]
326    then
327       echo " local_host = $local_host   ssh_status = $ssh_status"
328       locat=ssh_failed_1; exit
329    else
330       if [[ $(grep -c "*** list complete" $filelist) = 0 ]]
331       then
332          echo " local_host = $local_host   ssh_status = $ssh_status"
333          locat=ssh_failed_2; exit
334       fi
335    fi
336 fi
337
338
339    # PRUEFEN, OB VERZEICHNIS VORHANDEN IST. WENN GANZES VERZEICHNISS ZUM
340    # ZIELRECHNER KOPIERT WERDEN SOLL, DARF DORT NOCH KEIN ENTSPRECHENDES
341    # VERZEICHNIS VORHANDEN SEIN
342 if [[ $(cat $filelist | grep -c "not found") != 0  || \
343       $(cat $filelist | grep -c "No such file or directory") != 0 ]]
344 then
345    if [[ ! ( $catalog_copy = true  &&  $get = false ) ]]
346    then
347       if [[ $make_catalog = false ]]
348       then
349          printf " +++ directory \"$3\" does not exist on destination host (\"$1\") \n"
350          locat=directory; exit
351       else
352          if [[ $silent = false ]]
353          then
354             printf "  >>> directory \"$3\" does not exist on destination host (\"$1\")"
355             printf "\n      trying to create \"$3\" \n"
356          fi
357
358          make_catalog=force
359       fi
360    fi
361 fi
362
363
364    # PRUEFEN, OB DATEI/VERZEICHNIS VORHANDEN, WENN JA, HOECHSTEN ZYKLUS
365    # ERMITTELN (BZW. IM ABSOLUT-MODUS PRUEFEN, OB DATEI VORHANDEN IST)
366    # DAS GANZE ABER NUR, WENN NICHT OVERWRITE-MODUS GEWAEHLT WURDE, DIE
367    # EVENTUELL VORHANDENE DATEI ALSO UEBERSCHRIEBEN WERDEN SOLL
368 found=false
369 if [[ ( $overwrite = false   &&  $get = false )  ||  $get = true ]]
370 then
371    while  read zeile
372    do
373       if [[ $absolut = false ]]
374       then
375          text=$(echo $zeile | cut -f1 -d".")
376          if [[ "$text" = "$4" ]]
377          then
378             found=true
379             cycle=$(echo $zeile | cut -f2 -d".")
380             if [[ "$cycle" = "$text" ]]
381             then
382                (( icycle = 0 ))
383             else
384
385                   # PRUEFEN, OB CYCLE EINE ZAHL IST
386                (( iii = 1 ))
387                character=`echo $cycle | cut -c$iii`
388                character_found=false
389                while [[ "$character" != ""  &&  $character_found = false ]]
390                do
391                   case  $character  in
392                      (0|1|2|3|4|5|6|7|8|9)  true;;
393                      (*)  character_found=true
394                   esac
395                   (( iii = iii + 1 ))
396                   character=`echo $cycle | cut -c$iii`
397                done
398
399                if [[ $character_found = false ]]
400                then
401                   (( icycle = $cycle ))
402                fi
403             fi >|$errfile 2>&1    # AUSGABE FEHLER AUF ERRFILE WENN CYCLE NICHTNUMERISCH
404
405
406                # INFORMATIVE AUSGABE, WENN DATEI NICHTNUMERISCHE EXTENSION HAT
407                # if [[ $(cat $errfile | grep -c "bad number") != 0 ]]
408             if [[ $character_found = true ]]
409             then
410                if [[ $cycle != "$5" ]]
411                then
412                   printf "  +++ file \"$text\" has non-numerical extension \".$cycle\" \n"
413                   locat=file; exit
414                else
415                   if [[ $silent = false ]]
416                   then
417                      printf "  >>> file \"$text\" has non-numerical extension \".$cycle\" \n"
418                   fi
419                fi
420             fi
421
422             if (( icycle > maxcycle ))
423             then
424                (( maxcycle = icycle ))
425             fi
426          fi
427
428       else
429
430             # IM ABSOLUT-MODUS MUSS NUR GEPRUEFT WERDEN, OB DIE DATEI
431             # VORHANDEN IST
432          [[ $4 = $zeile ]]  &&  found=true
433       fi
434
435    done <$filelist
436 fi
437
438 if [[ $found = true ]]
439 then
440    if [[ $get = false ]]
441    then
442       if [[ $absolut = false ]]
443       then
444          if [[ $append = false ]]
445          then
446             (( maxcycle = maxcycle + 1 ))
447             zyklusnr=".$maxcycle"
448          else
449             if (( maxcycle == 0 ))
450             then
451                zyklusnr=""
452             else
453                zyklusnr=".$maxcycle"
454             fi
455          fi
456       else
457          if [[ $overwrite = false ]]
458          then
459             printf "  +++ file \"$3/$4\" \n"
460             printf "      already exists on destination host (use -o, if necessary) \n"
461             locat=file; exit
462          fi
463       fi
464    else
465       if [[ $absolut = false ]]
466       then
467          if (( maxcycle == 0 ))
468          then
469             zyklusnr=""
470          else
471             zyklusnr=".$maxcycle"
472             (( maxcycle = 0 ))
473          fi
474       else
475          zyklusnr=""
476       fi
477    fi
478 else
479    zyklusnr=""
480
481       # ABBRUCH, WENN DATEI VON ZIELRECHNER GEHOLT WERDEN SOLL, DORT ABER
482       # NICHT VORHANDEN IST
483    if [[ $get = true ]]
484    then
485       printf " +++ file \"$3/$4\" \n"
486       printf "     does not exist on destination host (\"$1\") \n"
487       locat=remotefile; exit
488    fi
489 fi
490
491
492    # FALLS KATALOG ERZEUGT WIRD, DARF DIE DATEI IN KEINEM FALL EINE
493    # ZYKLUSNUMMER BESITZEN, DA SIE JA NOCh GARNICHT EXISTIEREN KANN
494 if [[ $make_catalog = force ]]
495 then
496    zyklusnr=""
497    (( maxcycle = 0 ))
498 fi
499
500 
501    # FALLS NAMENSOPTION (-n) GEWAEHLT WURDE, NUR DEN ERMITTELTEN LOKALEN
502    # DATEINAMEN DES ZIELRECHNERS AUSGEBEN UND SCRIPT BEENDEN
503 if [[ $print_local_filename = true ]]
504 then
505    printf "$4$zyklusnr\n"
506    rm -r $filelist
507    exit
508 fi
509
510
511    # FALLS 5. ARGUMENT ANGEGEBEN WURDE, WIRD DIES ALS FILE-EXTENSION
512    # HINTER DIE ZYKLUS-NUMMER GEHAENGT (FUNKTIONIERT NUR BEI KOPIEREN EINER
513    # DATEI AUF ZIELRECHNER
514 if [[ "$5" != ""  &&  $get = false ]]
515 then
516    zyklusnr=${zyklusnr}.$5
517 fi
518
519
520    # BEI VERZEICHNISTRANSFER VON ZIELRECHNER AUF LOKALEN RECHNER PRUEFEN, OB
521    # $3 AUF ZIELRECHNER WIRKLICH EIN VERZEICHNIS IST
522 if [[ $catalog_copy = true  &&  $get = true ]]
523 then
524    rm -rf $filelist
[693]525    if [[ $(echo $local_host | cut -c1-4) = gaia ]]
526    then
[1094]527       ssh $SSH_PORTOPT $local_user@gaiad "ssh $1 -l $remote_user \"cd $3\" " > $filelist
[693]528    else
[1094]529       ssh $SSH_PORTOPT $1 -l $remote_user "cd $3" > $filelist
[693]530    fi
[1]531    if [[ $? != 0 ]]
532    then
533       locat=ssh_failed_3; exit
534    fi
535
536    if [[ $(cat $filelist | grep -c "Not a directory") != 0 ]]
537    then
538       printf " +++ \"$3\" on destination host is not a directory \n"
539       locat=directory; exit
540    fi
541 fi
542
543
544    # BEI KATALOGTRANSFER AUF LOKALEN RECHNER ENTSPRECHENDES VERZEICHNIS
545    # ANLEGEN
546 if [[ $catalog_copy = true ]]
547 then
548    if [[ $get = true ]]
549    then
550       mkdir $2
551    fi
552 fi
553
554
555    # Auf IBM-Rechnern (HLRN) Tilde aus Katalognamen entfernen, da scp
556    # diese nicht versteht
557 catalog_name=$3
558 if [[ $(hostname | cut -c1-4) = hreg  ||  $(hostname | cut -c1-4) = breg ]]
559 then
560    catalog_name=${catalog_name#"~/"}
561    catalog_name=${catalog_name#"~"}
562 fi
563 [[ "$catalog_name" != "" ]]  &&  catalog_name=${catalog_name}/
564
565
566    # DATEI/VERZEICHNIS PER SCP UEBERTRAGEN
567 if [[ $get = false ]]
568 then
569    if [[ $make_catalog != force ]]
570    then
571       if [[ $append = false ]]
572       then
573          if [[ $(echo $local_host | cut -c1-2) = cs ]]
574          then
575             if [[ $catalog_copy = false ]]
576             then
[1094]577                scp $PORTOPT -p -q -v $2 $remote_user@$1:$catalog_name$4$zyklusnr
[1]578             else
[1094]579                scp $PORTOPT -p -r -q -v $2 $remote_user@$1:$catalog_name$4$zyklusnr
[1]580             fi
[693]581          elif [[ $(echo $local_host | cut -c1-4) = gaia ]]
582          then
583             if [[ $catalog_copy = false ]]
584             then
[1094]585                ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
[693]586             else
[1094]587                ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
[693]588             fi
[1]589          else
590             if [[ $catalog_copy = false ]]
591             then
[1094]592                scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
[1]593             else
[1094]594                scp $PORTOPT -p -r $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
[1]595             fi
596          fi
597          scp_status=$?
598
599          if [[ $scp_status != 0 ]]
600          then
601                # CHECK, OB DATEIGROESSEN AUF LOKALEM UND REMOTERECHNER
602                # UEBEREINSTIMMEN
603             local_size=`ls -al  $2`
604             local_size=`echo $local_size | cut -d" " -f5`
605
[693]606             if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
607             then
[1094]608                remote_size=`ssh $SSH_PORTOPT $local_user@gaiad "ssh $SSH_PORTOPT $1 -l $remote_user \"ls -al $catalog_name$4$zyklusnr\" "`
[693]609             else
[1094]610                remote_size=`ssh $SSH_PORTOPT $1 -l $remote_user "ls -al $catalog_name$4$zyklusnr"`
[693]611             fi
[1]612             remote_size=`echo $remote_size | cut -d" " -f5`
613
614             if [[ "$remote_size" != "$local_size" ]]
615             then
616                echo " +++ scp failed on host \"$local_host\" with exit $scp_status"
617                echo "     local size = \"$local_size\"  remote size = \"$remote_size\" "
618                date
619                locat=scp_failed; exit
620             fi
621          fi
622       else
[693]623          if [[ $(echo $local_host | cut -c1-4) = gaia ]]
624          then
[1094]625             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]626          else
[1094]627             scp $PORTOPT -p $2 $remote_user@$1:${catalog_name}batch_scp_append_file.$random  > /dev/null
[693]628          fi
[1]629          if [[ $? != 0 ]]
630          then
631                # CHECK, OB DATEIGROESSEN AUF LOKALEM UND REMOTERECHNER
632                # UEBEREINSTIMMEN
633             local_size=`ls -al  $2`
634             local_size=`echo $local_size | cut -d" " -f5`
635
[693]636             if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
637             then
[1094]638                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]639             else
[1094]640                remote_size=`ssh $SSH_PORTOPT $1 -l $remote_user "ls -al ${catalog_name}batch_scp_append_file.$random"`
[693]641             fi
[1]642             remote_size=`echo $remote_size | cut -d" " -f5`
643
644             if [[ "$remote_size" != "$local_size" ]]
645             then
646                echo " +++ scp failed on host \"$local_host\" with exit $scp_status"
647                echo "     local size = \"$local_size\"  remote size = \"$remote_size\" "
648                date
649                locat=scp_for_append_failed; exit
650             fi
651          fi
652
653          rm  $filelist
654
[693]655          if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
656          then
[1094]657             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]658          else
[1094]659             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]660          fi
[1]661          if [[ $? != 0 ]]
662          then
663             if [[ ! -f $filelist ]]
664             then
665                locat=append_via_ssh_failed; exit
666             else
667                if [[ $(grep -c "*** append complete" $filelist) = 0 ]]
668                then
669                   locat=append_via_ssh_failed; exit
670                fi
671             fi
672          fi
673       fi
674    else
[693]675       if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
676       then
[1094]677          ssh $SSH_PORTOPT $local_user@gaiad "ssh $1 -l $remote_user \"mkdir -p $3\" "
[693]678       else
[1094]679          ssh $SSH_PORTOPT $1 -l $remote_user "mkdir -p $3"
[693]680       fi
[1]681       if [[ $? != 0 ]]
682       then
683          locat=ssh_failed_4; exit
684       fi
[693]685       if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
686       then
[1094]687          ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr"  > /dev/null
[693]688       else
[1094]689          scp $PORTOPT -p $2 $remote_user@$1:$catalog_name$4$zyklusnr  > /dev/null
[693]690       fi
[1]691       if [[ $? != 0 ]]
692       then
693          locat=scp_failed; exit
694       fi
695    fi
696
697 else
698
699    if [[ $catalog_copy = false ]]
700    then
701       if [[ $quote_wait = true ]]
702       then
703
704          printf " +++ quote wait not realized with BATCH_SCP"
705          locat=unavailable_feature; exit
706
707       else
708
[693]709          if  [[ $(echo $local_host | cut -c1-4) = gaia ]]
710          then
[1094]711             ssh $SSH_PORTOPT $local_user@gaiad "cd $local_wdir; scp $PORTOPT -p $remote_user@$1:$catalog_name$4$zyklusnr $2"  > /dev/null
[693]712          else
[1094]713             scp $PORTOPT -p $remote_user@$1:$catalog_name$4$zyklusnr $2  > /dev/null
[693]714          fi
[1]715          if [[ $? != 0 ]]
716          then
717             locat=scp_failed; exit
718          fi
719
720       fi
721    else
722
723       printf " +++ get of whole cataloges not realized with BATCH_SCP so far"
724       locat=unavailable_feature; exit
725
726#       ftp -i $1 << %END%  > /dev/null
727#$transfermode
728#cd $3
729#mget *
730#quit
731#%END%
732    fi
733 fi
734
735
736
737    # EVTL. TRANSFERIERTE DATEI AUF LOKALEM RECHNER LOESCHEN
738 if [[ $delete = true  &&  $get = false ]]
739 then
740    rm -rf  $2
741 fi
742
743
744
745    # ABSCHLUSSMELDUNG
746 if [[ $silent = false ]]
747 then
748    if (( maxcycle == 0 ))
749    then
750       if [[ $append = false ]]
751       then
752          printf "  >>> transfer successful \n"
753       else
754          printf "  >>> file was appended \n"
755       fi
756    else
757       printf "  >>> transfer successful \n"
758       if [[ $append = false ]]
759       then
760          if [[ $catalog_copy = false ]]
761          then
762             printf "      new file has cycle number $maxcycle \n"
763          else
764             printf "      new catalog has cycle number $maxcycle \n"
765          fi
766       else
767          printf "      append to cycle number $maxcycle \n"
768       fi
769    fi
770 fi
771
772 rm -rf  $filelist  $errfile
Note: See TracBrowser for help on using the repository browser.