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