source: palm/trunk/SCRIPTS/batch_scp @ 3136

Last change on this file since 3136 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

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