Index: trunk/MagicSoft/Mars/datacenter/scripts/jobmanager
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/jobmanager	(revision 8114)
+++ trunk/MagicSoft/Mars/datacenter/scripts/jobmanager	(revision 8115)
@@ -36,7 +36,4 @@
 echo "" >> $jmscriptlog 2>&1
 echo "starting jobmanager ("`date`")" >> $jmscriptlog 2>&1
-makedir $jmlogpath
-makedir $listpath >> $jmscriptlog 2>&1
-makedir $lockpath >> $jmscriptlog 2>&1
 
 prev=$max
@@ -47,17 +44,23 @@
    for (( i=0 ; i < ${#scripts[@]} ; i++ ))
    do 
-      makedir $jmlogpath
       date  >> $jmscriptlog 2>&1
+      source `dirname $0`/sourcefile
+      echo "script: ${scripts[$i]}" >> $jmscriptlog 2>&1
+
+      # check if there's something to do
+      getstatus >> $jmscriptlog 2>&1
+      echo " $numproc ${scripts[$i]} still do to" >> $jmscriptlog 2>&1
+      if [ "$numproc" = "" ]
+      then 
+         prev=0
+         cont >> $jmscriptlog 2>&1
+      fi
+      prev=$max
+
       echo "sleeping $sleeptime..." >> $jmscriptlog 2>&1
       sleep $sleeptime
-      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 -eq 0 ]
-      if [ "$queued" = "" ]
+      q=(`/usr/local/bin/condor_q -global -format "Owner%s " Owner -format "%s" CMD -format "Jobstatus%s\n" Jobstatus`)
+      if echo $q | egrep \(Error\|failed\)
       then 
          printprocesslog "WARN condor_q failed"
@@ -65,23 +68,20 @@
          cont >> $jmscriptlog 2>&1
       fi
-      queuedscript=`/usr/local/bin/condor_q -global | grep $user | grep -c ${scripts[$i]}`
-      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]}`
-      if [ "$runningscript" = "" ]
-      then 
-         printprocesslog "WARN condor_q failed"
-         echo `date`"ERROR condor_q failed" >> $jmerrorlog
-         cont >> $jmscriptlog 2>&1
-      fi
+      q1=(`echo ${q[@]} | egrep -o Owner$user`)
+      queued=${#q1[@]}
+      
+      q2=(`echo ${q[@]} | egrep -o ${scripts[$i]}`)
+      queuedscript=${#q2[@]}
+      
+      q3=(`echo ${q[@]} | egrep -o ${scripts[$i]}Jobstatus2`)
+      runningscript=${#q3[@]}
       stillinqueue=`echo $queuedscript - $runningscript | bc `
 
+      #get total number of allowed process for current time
+      hour=`date +%k`
       totalpno=${pnototal[$hour]}
       
       #choose array according to the day of the week
+      dayofweek=`date +%u`
       case $dayofweek in
          0 | 6)  pnos=( ${pnoswe[@]} ) ;;
@@ -98,22 +98,9 @@
       echo " found $queuedscript ${scripts[$i]} in the queue (incl. running jobs [$runningscript]) [allowed $pnoscript] - not running: $stillinqueue" >> $jmscriptlog 2>&1
       
-      if [ "$queued" -gt "$totalpno" ]
-      then
-         cont >> $jmscriptlog 2>&1
-      fi
-      if [ "$queuedscript" -gt "$pnoscript" ]
+      if [ "$queued" -gt "$totalpno" ] || [ "$queuedscript" -gt "$pnoscript" ]
       then
          cont >> $jmscriptlog 2>&1
       fi
 
-      # check if there's something to do
-      getstatus >> $jmscriptlog 2>&1
-      echo " $numproc ${scripts[$i]} still do to" >> $jmscriptlog 2>&1
-      if [ "$numproc" = "" ]
-      then 
-         prev=0
-         cont >> $jmscriptlog 2>&1
-      fi
-      prev=$max
       if [ $numproc -lt $stillinqueue ]
       then 
Index: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 8114)
+++ trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 8115)
@@ -66,4 +66,6 @@
 processlog=$processlogpath/process`date +%F`.log
 
+makedir $lockpath
+makedir $listpath
 
 # set checkvalue to ok at the beginning of the scripts
