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