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