source: palm/trunk/SCRIPTS/batch_scp @ 3994

Last change on this file since 3994 was 3549, checked in by raasch, 6 years ago

ssh-call for submitting batch jobs on remote systems modified to avoid output of login messages on specific systems, ssh-calls for compilations on remote systems modified to avoid output of login messages on specific systems, english translation of german comments / variable names

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