Index: trunk/Mars/datacenter/scripts/runcallisto_mc
===================================================================
--- trunk/Mars/datacenter/scripts/runcallisto_mc	(revision 10040)
+++ trunk/Mars/datacenter/scripts/runcallisto_mc	(revision 10041)
@@ -37,16 +37,30 @@
 
 # get sequence # 
-gettodo "1" 
-sequence=${primaries[0]}
-cereskey=${primaries[1]}
-
-# lock sequ for cal
-lockfile=$lockpath/lock-$step-$sequence-$cereskey.txt
-checklock 
+numchanged=0
+while (( 0 < 21 ))
+do 
+   if ! [ $numchanged -eq 1 ]
+   then 
+      if ! [ "$sequence" = "" ] && ! [ "$cereskey" = "" ]
+      then
+         printprocesslog "INFO $program for sequence $sequence cereskey $cereskey is already running => request new number "
+      fi
+      gettodo "1" 
+      sequence=${primaries[0]}
+      cereskey=${primaries[1]}
+      if [ "$sequence" = "" ] || [ "$cereskey" = "" ]
+      then
+         printprocesslog "INFO nothing to do for $program "
+      fi
+   else
+      printprocesslog "INFO starting $program for sequence $sequence cereskey $cereskey"
+      break
+   fi
+   setstatus "start"
+done
 
 cd $mars
 
 # run calibration for sequence
-printprocesslog "INFO starting $program for sequence $sequence cereskey $cereskey"
 
 # define files and paths
@@ -57,6 +71,4 @@
 callistorc=$setuppath/$program/`printf %03d $cereskey`/callisto.rc
 inpath=$mcpath/ceres/`printf %03d $cereskey`/`printf %08d $sequence | cut -c 1-4`/`printf %08d $sequence | cut -c 5-8`
-
-setstatus "start"
 
 command="./callisto -b -q -v4 -f --out=$outpath --ind=$inpath --log=$log.log --html=$log.html --config=$callistorc $sequfile"
Index: trunk/Mars/datacenter/scripts/runceres
===================================================================
--- trunk/Mars/datacenter/scripts/runceres	(revision 10040)
+++ trunk/Mars/datacenter/scripts/runceres	(revision 10041)
@@ -37,19 +37,31 @@
 set -C
 
-# get sequence # 
-gettodo "1"
-run=${primaries[0]}
-cereskey=${primaries[1]}
-
-# lock sequ for cal
-lockfile=$lockpath/lock-$step-$run.$cereskey.txt
-checklock
+# get run # 
+numchanged=0
+while (( 0 < 21 ))
+do 
+   if ! [ $numchanged -eq 1 ]
+   then 
+      if ! [ "$run" = "" ] && ! [ "$cereskey" = "" ]
+      then
+         printprocesslog "INFO $program for run $run cereskey $cereskey is already running => request new number "
+      fi
+      gettodo "1" 
+      run=${primaries[0]}
+      cereskey=${primaries[1]}
+      if [ "$run" = "" ] || [ "$cereskey" = "" ]
+      then
+         printprocesslog "INFO nothing to do for $program "
+      fi
+   else
+      printprocesslog "INFO starting $program for run $run cereskey $cereskey"
+      break
+   fi
+   setstatus "start"
+done
 
 cd $mars
 
-# run calibration for sequence
-printprocesslog "INFO starting $program for run $run and ceres-setup $cereskey"
-
-setstatus "start"
+# run ceres for run
 
 setupfile=$setuppath/$program/`printf %03d $cereskey`/ceres.rc
Index: trunk/Mars/datacenter/scripts/runcorsika
===================================================================
--- trunk/Mars/datacenter/scripts/runcorsika	(revision 10040)
+++ trunk/Mars/datacenter/scripts/runcorsika	(revision 10041)
@@ -144,17 +144,29 @@
 
 
-# get sequence # 
-gettodo "1" 
-run=${primaries[0]}
-file=${primaries[1]}
-
-# lock sequ
-lockfile=$lockpath/lock-$step-$run.$file.txt
-checklock 
-
-printprocesslog "INFO starting $program for run $run and file $file"
-
-setstatus "start" 
-
+# get run # and file #
+numchanged=0
+while (( 0 < 21 ))
+do 
+   if ! [ $numchanged -eq 1 ]
+   then 
+      if ! [ "$run" = "" ] && ! [ "$file" = "" ]
+      then
+         printprocesslog "INFO $program for run $run and file $file is already running => request new number "
+      fi
+      gettodo "1" 
+      run=${primaries[0]}
+      file=${primaries[1]}
+      if [ "$run" = "" ] || [ "$file" = "" ]
+      then
+         printprocesslog "INFO nothing to do for $program "
+      fi
+   else
+      printprocesslog "INFO starting $program for run $run and file $file"
+      break
+   fi
+   setstatus "start"
+done
+
+# running corsika
 printprocesslog "INFO run $program for run $run  and file $file" 
 printprocesslog "INFO create input card for run $run  and file $file" 
Index: trunk/Mars/datacenter/scripts/runstar_mc
===================================================================
--- trunk/Mars/datacenter/scripts/runstar_mc	(revision 10040)
+++ trunk/Mars/datacenter/scripts/runstar_mc	(revision 10041)
@@ -36,16 +36,30 @@
 
 # get sequence # 
-gettodo "1" 
-sequence=${primaries[0]}
-cereskey=${primaries[1]}
-
-# lock sequ for cal
-lockfile=$lockpath/lock-$step-$sequence-$cereskey.txt
-checklock 
+numchanged=0
+while (( 0 < 21 ))
+do 
+   if ! [ $numchanged -eq 1 ]
+   then 
+      if ! [ "$sequence" = "" ] && ! [ "$cereskey" = "" ]
+      then
+         printprocesslog "INFO $program for sequence $sequence cereskey $cereskey is already running => request new number "
+      fi
+      gettodo "1" 
+      sequence=${primaries[0]}
+      cereskey=${primaries[1]}
+      if [ "$sequence" = "" ] || [ "$cereskey" = "" ]
+      then
+         printprocesslog "INFO nothing to do for $program "
+      fi
+   else
+      printprocesslog "INFO starting $program for sequence $sequence cereskey $cereskey"
+      break
+   fi
+   setstatus "start"
+done
 
 cd $mars
 
 # run calibration for sequence
-printprocesslog "INFO starting $program for sequence $sequence cereskey $cereskey"
 
 # define files and paths
@@ -55,6 +69,4 @@
 log=$outpath/$program`printf %08d $sequence`
 inpath=$mcpath/callisto/`printf %03d $cereskey`/`printf %08d $sequence | cut -c 1-4`/`printf %08d $sequence | cut -c 5-8`
-
-setstatus "start"
 
 command="./star -b -q -v4 -f --ind=$inpath --out=$outpath --log=$log.log --html=$log.html $sequfile"
Index: trunk/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/Mars/datacenter/scripts/sourcefile	(revision 10040)
+++ trunk/Mars/datacenter/scripts/sourcefile	(revision 10041)
@@ -48,9 +48,9 @@
    export SOURCEFILEPATH=`dirname $0`
 fi
-
-# possible solution for $0 problem: 
-# ${BASH_SOURCE[0]} 
-# but has to be checked and tested more carefully
-# should solve at least problem with login-shell and with source
+if [ "$SCRIPTNAME" = "" ]
+then 
+   SCRIPTNAME=`basename $0`
+fi
+
 source $SOURCEFILEPATH/setup.$AUTOMATIONSETUP
 
@@ -68,5 +68,5 @@
          if ! [ "$processlog" = "" ]
          then
-            echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] ERROR could not make dir "$@ >> $processlog
+            echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "$SCRIPTNAME"["$$"] ERROR could not make dir "$@ >> $processlog
          else
             echo "could not make dir "$@
@@ -95,5 +95,5 @@
 {
    makedir $processlogpath
-   echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] "$@ >> $processlog
+   echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "$SCRIPTNAME"["$$"] "$@ >> $processlog
 }
 
@@ -105,5 +105,5 @@
       printprocesslog "DEBUG " `rm -v $lockfile`
    fi
-   printprocesslog "DEBUG finished $0"
+   printprocesslog "DEBUG finished "$SOURCEFILEPATH"/"$SCRIPTNAME
    exit
 }
@@ -153,5 +153,5 @@
 function checklock()
 {
-   if ! echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] "`uname -a` > $lockfile 2>/dev/null
+   if ! echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "$SCRIPTNAME"["$$"] "`uname -a` > $lockfile 2>/dev/null
    then 
       printprocesslog "WARN lockfile $lockfile exists"
@@ -424,12 +424,25 @@
    do
       query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"='${primaries[$s*${#prims[@]}+$j]}' "
-   done   
+   done 
+   # add additional query to allow for locking in db
+   if [ "$1" = "start" ]
+   then 
+      query=$query" AND ISNULL("$step"Status.fStartTime) "
+   fi
+   # add row count to know how many rows have been changed
+   query=$query"; SELECT ROW_COUNT();"
    # print query
    printprocesslog "DEBUG setstatus for step $step QUERY: "$query
    # execute query
-   if ! mysql -s -u $us --password=$pw --host=$ho $db -e " $query "
+   if ! numchanged=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "`
    then
       printprocesslog "ERROR could not set status in db (program: $program, function setstatus)"
       finish
+   fi
+   if [ $numchanged -gt 0 ]
+   then
+      printprocesslog "INFO successful setting of status in db (program: $program, function setstatus)"
+   else
+      printprocesslog "INFO status in db was already set by other process (program: $program, function setstatus)"
    fi
 }
