Index: palm/trunk/SCRIPTS/batch_scp
===================================================================
--- palm/trunk/SCRIPTS/batch_scp	(revision 1310)
+++ palm/trunk/SCRIPTS/batch_scp	(revision 2261)
@@ -1,3 +1,3 @@
-#! /bin/ksh
+#! /bin/bash
 
 # batch_scp - script for automatic file/directory transfer using scp
@@ -22,9 +22,13 @@
 # Current revisions:
 # ------------------
-#
-#
+# 
+# 
 # Former revisions:
 # -----------------
 # $Id$
+# option usecycle added, script is running under bash now,
+# filenames are allowed to contain arbitrary number of dots "."
+#
+# 1310 2014-03-14 08:01:56Z raasch
 #
 # 1202 2013-07-10 16:22:07Z witha
@@ -52,9 +56,10 @@
 # batch_scp - script for automatic file/directory transfers using scp
 #
-# batch_scp has 4 arguments:
+# batch_scp has up to 5 arguments (first 4 are mandatory):
 #               $1 = IP-addres of remote (target) machine
 #               $2 = file to be transferred
 #               $3 = directory of remote machine, where file should be copied to
 #               $4 = filename that file should be given on remote machine
+#               $5 = file extension (optional argument)
 #
 # ATTENTION: problems might occur if directories on remote machine include very
@@ -89,5 +94,5 @@
  transfermode=binary
  zyklusnr=""
- typeset -i iii icycle maxcycle=0 wait=0
+ typeset -i iii icycle maxcycle=0 usecycle wait=0
 
     # FEHLERBEHANDLUNG
@@ -113,5 +118,5 @@
 
     # SHELLSCRIPT-OPTIONEN EINLESEN
- while  getopts  :aAbcCdgmnoP:qsu:w:  option
+ while  getopts  :aAbcCdgmnoP:qsu:U:w:  option
  do
    case  $option  in
@@ -130,4 +135,5 @@
        (s)   silent=true;;
        (u)   remote_user=$OPTARG;;
+       (U)   usecycle=$OPTARG;;
        (w)   wait=$OPTARG;;
        (\?)  printf "  +++ option $OPTARG unknown \n"
@@ -136,5 +142,8 @@
    esac
  done
- shift OPTIND-1
+
+ (( to_shift = $OPTIND - 1 ))
+ shift $to_shift
+
 
 
@@ -144,5 +153,5 @@
  then
    (printf "\n  *** batch_scp can be called as follows:\n"
-    printf "\n      batch_scp -a -b -d -g -o -q -s -u.. -w..  <param1> <param2> <param3> <param4>\n"
+    printf "\n      batch_scp -a -b -d -g -o -q -s -u.. -U.. -w..  <param1> <param2> <param3> <param4>\n"
     printf "\n      Description of available options:\n"
     printf "\n      Option  Description                            Default-Value"
@@ -163,4 +172,5 @@
     printf "\n        -s    do not display informative messages    ---"
     printf "\n        -u    username on remote machine             <username>"
+    printf "\n        -U    cycle number to be used                ---"
     printf "\n        -w    waiting time in seconds, before trans- 0"
     printf "\n              fer will be initiated"
@@ -226,14 +236,4 @@
 
 
-    # DATEINAME IM 4. ARGUMENT DARF NUR BEIM UEBERSCHREIBEN ODER IM ABSOLUT-
-    # MODUS PUNKTE ENTHALTEN
- if [[ $overwrite = false  &&  $absolut = false  &&  $(echo $4 | grep -c "\.") != 0 ]]
- then
-    printf " +++ 4th argument may only contain dots (".") , if one of the \n"
-    printf "     options -a or -o are given \n"
-    locat=argument; exit
- fi
-
-
     # QUOTE WAIT FUNKTIONIERT NICHT BEIM KOPIEREN GANZER VERZEICHNISSE
  if [[ $quote_wait = true  &&  $catalog_copy = true ]]
@@ -386,50 +386,96 @@
        if [[ $absolut = false ]]
        then
-          text=$(echo $zeile | cut -f1 -d".")
-          if [[ "$text" = "$4" ]]
-          then
-             found=true
-             cycle=$(echo $zeile | cut -f2 -d".")
-             if [[ "$cycle" = "$text" ]]
-             then
+             # REMOVE EXTENSION, IF EXISTING AND GIVEN AS ARGUMENT
+          if [[ "$5" != ""  &&  "$5" != " " ]]
+          then
+             extension=${zeile##*.}
+             if [[ $extension = $5 ]]
+             then
+                text=${zeile%.*}
+             else
+                text=${zeile}
+             fi
+          else
+             text=${zeile}
+          fi
+
+             # GET AND REMOVE CYCLE NUMBER, IF EXISTING, AND CHECK, IF FILE EXISTS
+          cycle=${text##*.}
+          if [[ $cycle = $text ]]
+          then
+                # filename contains no dot, i.e. no cycle number
+             if [[ "$text" = "$4" ]]
+             then
+                found=true
                 (( icycle = 0 ))
-             else
-
-                   # PRUEFEN, OB CYCLE EINE ZAHL IST
-                (( iii = 1 ))
-                character=`echo $cycle | cut -c$iii`
-                character_found=false
-                while [[ "$character" != ""  &&  $character_found = false ]]
-                do
-                   case  $character  in
-                      (0|1|2|3|4|5|6|7|8|9)  true;;
-                      (*)  character_found=true
-                   esac
-                   (( iii = iii + 1 ))
-                   character=`echo $cycle | cut -c$iii`
-                done
-
-                if [[ $character_found = false ]]
+             fi
+          else
+                # filename contains at least one dot
+                # find out if the string after the last dot is a number
+             if [[ $cycle =~ ^-?[0-9]+$ ]]
+             then
+                text=${text%.*}
+                if [[ "$text" = "$4" ]]
                 then
+                   found=true
                    (( icycle = $cycle ))
                 fi
-             fi >|$errfile 2>&1    # AUSGABE FEHLER AUF ERRFILE WENN CYCLE NICHTNUMERISCH
-
-
-                # INFORMATIVE AUSGABE, WENN DATEI NICHTNUMERISCHE EXTENSION HAT
-                # if [[ $(cat $errfile | grep -c "bad number") != 0 ]]
-             if [[ $character_found = true ]]
-             then
-                if [[ $cycle != "$5" ]]
+             else
+                if [[ "$text" = "$4" ]]
                 then
-                   printf "  +++ file \"$text\" has non-numerical extension \".$cycle\" \n"
-                   locat=file; exit
-                else
-                   if [[ $silent = false ]]
-                   then
-                      printf "  >>> file \"$text\" has non-numerical extension \".$cycle\" \n"
-                   fi
+                   found=true
+                   (( icycle = 0 ))
                 fi
              fi
+          fi
+
+
+#          text=$(echo $zeile | cut -f1 -d".")
+#
+#          if [[ "$text" = "$4" ]]
+#          then
+#             found=true
+#             cycle=$(echo $zeile | cut -f2 -d".")
+#             if [[ "$cycle" = "$text" ]]
+#             then
+#                (( icycle = 0 ))
+#             else
+#
+#                   # PRUEFEN, OB CYCLE EINE ZAHL IST
+#                (( iii = 1 ))
+#                character=`echo $cycle | cut -c$iii`
+#                character_found=false
+#                while [[ "$character" != ""  &&  $character_found = false ]]
+#                do
+#                   case  $character  in
+#                      (0|1|2|3|4|5|6|7|8|9)  true;;
+#                      (*)  character_found=true
+#                   esac
+#                   (( iii = iii + 1 ))
+#                   character=`echo $cycle | cut -c$iii`
+#                done
+#
+#                if [[ $character_found = false ]]
+#                then
+#                   (( icycle = $cycle ))
+#                fi
+#             fi >|$errfile 2>&1    # AUSGABE FEHLER AUF ERRFILE WENN CYCLE NICHTNUMERISCH
+#
+#
+#                # INFORMATIVE AUSGABE, WENN DATEI NICHTNUMERISCHE EXTENSION HAT
+#                # if [[ $(cat $errfile | grep -c "bad number") != 0 ]]
+#             if [[ $character_found = true ]]
+#             then
+#                if [[ $cycle != "$5" ]]
+#                then
+#                   printf "  +++ file \"$text\" has non-numerical extension \".$cycle\" \n"
+#                   locat=file; exit
+#                else
+#                   if [[ $silent = false ]]
+#                   then
+#                      printf "  >>> file \"$text\" has non-numerical extension \".$cycle\" \n"
+#                   fi
+#                fi
+#             fi
 
              if (( icycle > maxcycle ))
@@ -437,5 +483,5 @@
                 (( maxcycle = icycle ))
              fi
-          fi
+#          fi
 
        else
@@ -458,4 +504,14 @@
           then
              (( maxcycle = maxcycle + 1 ))
+                # TRY TO USE FIXED CYCLE NUMBER, IF GIVEN AS OPTION
+             if [[ "$usecycle" != "" ]]
+             then
+                if (( usecycle >= maxcycle ))
+                then
+                   (( maxcycle = usecycle ))
+                else
+                    printf "  >>> Unfied cycle number cannot be used\n"
+                fi
+             fi
              zyklusnr=".$maxcycle"
           else
@@ -489,6 +545,14 @@
        fi
     fi
+
  else
-    zyklusnr=""
+
+    if [[ "$usecycle" != "" ]]
+    then
+       (( maxcycle = usecycle ))
+       zyklusnr=".$usecycle"
+    else
+       zyklusnr=""
+    fi
 
        # ABBRUCH, WENN DATEI VON ZIELRECHNER GEHOLT WERDEN SOLL, DORT ABER
