source: palm/trunk/SCRIPTS/batch_scp @ 1090

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

script adjustments for Kyushu-University computing center (lckyut)

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