Index: trunk/MagicSoft/Mars/datacenter/scripts/jobmanager
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/jobmanager	(revision 7958)
+++ trunk/MagicSoft/Mars/datacenter/scripts/jobmanager	(revision 7959)
@@ -29,5 +29,4 @@
 #
 
-
 source `dirname $0`/sourcefile
 printprocesslog "INFO starting $0"
@@ -54,13 +53,30 @@
       dayofweek=`date +%u`
       hour=`date +%k`
+
       source `dirname $0`/sourcefile
       echo "script: ${scripts[$i]}" >> $jmscriptlog 2>&1
 #      echo " day: $dayofweek hour: $hour" >> $jmscriptlog 2>&1
-      queued=`/usr/local/bin/condor_q -global -format "%s\n" Owner | grep -c $user`
-      queued=`setzero $queued`
+
+      queued=`/usr/local/bin/condor_q -global -format "%s\n" Owner | grep -c $user` && ! [ $queued -eq 0 ]
+      if [ "$queued" = "" ]
+      then 
+         printprocesslog "WARN condor_q failed"
+         echo `date`"ERROR condor_q failed" >> $jmerrorlog
+         cont >> $jmscriptlog 2>&1
+      fi
       queuedscript=`/usr/local/bin/condor_q -global | grep $user | grep -c ${scripts[$i]}`
-      queuedscript=`setzero $queuedscript`
+      if [ "$queuedscript" = "" ]
+      then 
+         printprocesslog "WARN condor_q failed"
+         echo `date`"ERROR condor_q failed" >> $jmerrorlog
+         cont >> $jmscriptlog 2>&1
+      fi
       runningscript=`/usr/local/bin/condor_q -global | grep $user | grep ' R ' | grep -c ${scripts[$i]}`
-      runningscript=`setzero $runningscript`
+      if [ "$runningscript" = "" ]
+      then 
+         printprocesslog "WARN condor_q failed"
+         echo `date`"ERROR condor_q failed" >> $jmerrorlog
+         cont >> $jmscriptlog 2>&1
+      fi
       stillinqueue=`echo $queuedscript - $runningscript | bc `
 
@@ -85,9 +101,8 @@
       then
          cont >> $jmscriptlog 2>&1
-      else
-         if [ "$queuedscript" -gt "$pnoscript" ]
-         then
-            cont >> $jmscriptlog 2>&1
-         fi
+      fi
+      if [ "$queuedscript" -gt "$pnoscript" ]
+      then
+         cont >> $jmscriptlog 2>&1
       fi
 
@@ -111,8 +126,7 @@
       if ! /usr/local/bin/condor_submit -a path=$scriptspath -a prog=${scripts[$i]} -a date=$date -a dir=$runlogpath $scriptspath/run.condor 2>> $jmerrorlog
       then 
-         date >> $jmerrorlog
-         nail -s 'condor problem'  $erradrs < $jmerrorlog
+         echo `date`"ERROR condor_submit failed" >> $jmerrorlog
          echo "condor is not working -> sleeping $errorsleeptime" >> $jmscriptlog 2>&1
-         printprocesslog "ERROR submitting ${scripts[$i]} to condor failed"
+         printprocesslog "WARN submitting ${scripts[$i]} to condor failed"
          sleep $errorsleeptime
       fi
Index: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 7958)
+++ trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 7959)
@@ -39,9 +39,30 @@
 webpath=/www/htdocs/datacenter
 
+datetime=`date +%F-%H-%M-%S`
+
+
+# function to make sure that a directory is made
+function makedir()
+{
+   if [ ! -d $@ ]
+   then
+     mkdir -pv $@ 
+     if [ ! -d $@ ]
+     then 
+        echo "could not make dir "$@
+        finish
+     fi
+   fi
+}
+
+# logging paths for runlogs and processlog
 runlogpath=$logpath/run/`date +%Y/%m/%d`
 processlogpath=$logpath/processlog
-
-datetime=`date +%F-%H-%M-%S`
-
+makedir $runlogpath
+makedir $processlogpath
+processlog=$processlogpath/process`date +%F`.log
+
+
+# set checkvalue to ok at the beginning of the scripts
 check="ok"
 
@@ -73,9 +94,8 @@
 Ffillganymed=21
 
-#
-# setup for jobmanager
-#
-#log files (can't be defined in script itself, as script can run longer 
-#than one day
+
+# setup for jobmanager:
+#   log files (can't be defined in script itself, as script can run longer 
+#   than one day
 jmerrorlog=$runlogpath/jobmanager-error`date +%F`.log
 jmscriptlog=$runlogpath/jobmanager`date +%F`.log
@@ -90,45 +110,10 @@
 stillinqueue=0
 
-function setzero()
-{
-   val=$@
-   if [ "$val" == "" ]
-   then 
-      test=`condor_q -global`
-      if [ "$test" == "" ]
-      then 
-         echo $max
-      else
-         echo 0
-      fi
-   else
-      echo $val
-   fi
-}
-
-
 
 # alias
 alias 'intgrep'='grep -E ^\\\(int\\\)[0-9]+$ | sed -e s\/\(int\)\/\/'
 
-# in the following the function, which are needed by several scripts, are 
+# in the following the functions, which are needed by several scripts, are 
 # defined
-
-# function to make sure that a directory is made
-function makedir()
-{
-   if [ ! -d $@ ]
-   then
-     mkdir -pv $@ 
-     if [ ! -d $@ ]
-     then 
-        echo "could not make dir "$@
-        finish
-     fi
-   fi
-}
-makedir $runlogpath
-makedir $processlogpath
-processlog=$processlogpath/process`date +%F`.log
 
 function printprocesslog
@@ -137,5 +122,5 @@
    echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] "$@ >> $processlog
 }
-   
+
 # function to exit a script properly
 function finish()
@@ -143,5 +128,5 @@
    rm -v $todofile
    rm -v $lockfile
-   date 
+   date
    printprocesslog "INFO finished $program"
    exit
@@ -158,11 +143,11 @@
 # function to check if a process is already locked
 function checklock()
-{ 
+{
    date > $lockfile
    checklock0=$?
-   case $checklock0 in 
+   case $checklock0 in
        0)   echo " checklock0=$checklock0 -> continue " ;;
        1)   echo " checklock0=$checklock0 -> file $lockfile exists -> exit"
-            date 
+            date
             exit;;
        *)   echo " checklock0=$checklock0 -> something went completely wrong" ;;
@@ -176,5 +161,5 @@
    year=`date +%Y`
    date=NULL
-   
+
    getstatuslogpath=$logpath/getstatus/$program/$year
    getstatuslog=$getstatuslogpath/getstatus-$table-$column-$datetime.log
@@ -219,5 +204,5 @@
 function evalstatus()
 {
-   case $@ in 
+   case $@ in
       start)   echo "setstatus start"
                starttime="Now()"
@@ -235,5 +220,5 @@
                       failedcode=$com
                       if ! [ "$comadd" = "" ]
-                      then 
+                      then
                          failedcodeadd=$comadd
                       fi
@@ -258,5 +243,5 @@
 
 #   printstatusvalues
-   # set status 
+   # set status
    setstatuslogpath=$logpath/setstatus/$program/$var1
    makedir $setstatuslogpath
@@ -298,10 +283,10 @@
 {
    echo "getting todolist..."
-   getdbsetup 
+   getdbsetup
    getstepinfo
    # get query
    query=" select $primary from $table where "
-   if ! echo $needs | grep '#' > /dev/null 
-   then 
+   if ! echo $needs | grep '#' > /dev/null
+   then
       for need in $needs
       do
@@ -322,9 +307,9 @@
    if [ "$process" = "" ]
    then
-      echo "  => nothing to do" 
-      finish
-   else 
+      echo "  => nothing to do"
+      finish
+   else
       todofile=$listpath/ToDo-$table-$column.txt
-      
+
       if ls $todofile > /dev/null 2>&1
       then
@@ -343,10 +328,10 @@
    process=
    echo "getting todo..."
-   getdbsetup 
+   getdbsetup
    getstepinfo
    # get query
    query=" select $primary from $table where "
-   if ! echo $needs | grep '#' > /dev/null 
-   then 
+   if ! echo $needs | grep '#' > /dev/null
+   then
       for need in $needs
       do
@@ -368,5 +353,5 @@
    if [ "$process" = "" ]
    then
-      echo "  => nothing to do -> exit" 
+      echo "  => nothing to do -> exit"
       finish
    fi
@@ -378,11 +363,11 @@
    numproc=
 #   echo "getting status..."
-   getdbsetup 
+   getdbsetup
    column=${scriptscolname[$i]}
    getstepinfo
    # get query
    query=" select count(*) from $table where "
-   if ! echo $needs | grep '#' > /dev/null 
-   then 
+   if ! echo $needs | grep '#' > /dev/null
+   then
       for need in $needs
       do
@@ -394,4 +379,5 @@
    query=$query" group by $column "
 #   echo " QUERY: "$query
+   numproc=0
    if ! numproc=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
    then
@@ -407,5 +393,5 @@
    resetstatusvalues
    evalstatus $@
-   getdbsetup 
+   getdbsetup
    getstepinfo
    # get query
@@ -413,18 +399,18 @@
    if [ "$reset" = "no" ]
    then
-      echo "YOU CAN'T RESET $column for $var2!!!" 
+      echo "YOU CAN'T RESET $column for $var2!!!"
       printprocesslog "ERROR you can't reset $column for $var2"
       finish
    fi
    query=" update $table set $column=$statustime"
-   if ! echo $influences | grep '#' > /dev/null 
-   then 
+   if ! echo $influences | grep '#' > /dev/null
+   then
       for influence in $influences
-      do 
+      do
          query=$query", $influence=NULL"
       done
    fi
    if ! [ "$starttime" = "noreset" ]
-   then 
+   then
       query=$query", fStartTime=$starttime"
    fi
@@ -433,5 +419,5 @@
    echo " QUERY: "$query
    if ! mysql -s -u $us --password=$pw --host=hercules $db -e " $query "
-   then 
+   then
       echo "ERROR could not insert status into db -> exit"
       printprocesslog "ERROR could not set status in db (program: $program, function setstatus)"
@@ -440,2 +426,3 @@
 
 }
+
