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