ProcessNewFiles.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 args=("$@")
4 argssize=${#args[*]}
5 if [ $argssize -ne 3 ];then
6  echo ""
7  echo "Usage: ./ProcessNewFiles.sh {maximum number of jobs to run} {version} {compiler}"
8  echo ""
9  echo "Example: ./ProcessNewFiles.sh 4 v04_30_03 e9"
10  echo ""
11  echo ""
12  exit
13 fi
14 
15 maxjobs=${args[0]}
16 version=${args[1]}
17 comp=${args[2]}
18 
19 echo ""
20 echo "Processing 35t nearline with maxjobs: $maxjobs"
21 echo ""
22 echo ""
23 
24 
25 
26 # Check Disk space before making a mess
27 export DiskUsage=`df /home -h | awk 'NR==2 && match($5,"%"){print substr($5,RSTART-3,2)}'`
28 if [ $DiskUsage -gt 95 ];then
29  echo ""
30  echo "Disk too full..."
31  echo "nearline home disk for 35t machine is $DiskUsage % full."
32  echo "All processing will be stopped until you clear out some space."
33  echo ""
34  echo ""
35  exit
36 fi
37 
38 export DiskUsage2=`df /lbne/data2 -h | awk 'NR==3 && match($4,"%"){print substr($4,RSTART-3,2)}'`
39 if [ $DiskUsage2 -gt 95 ];then
40  echo ""
41  echo "Disk too full..."
42  echo "nearline-data disk for 35t machine is $DiskUsage % full."
43  echo "All processing will be stopped until you clear out some space."
44  echo ""
45  echo ""
46  exit
47 fi
48 
49 
50 
51 # Test to see if this job is already running.
52 if [ -e /tmp/Batch-35t-Nearline.LOCK ];then
53  if [ $(( $(date +%s) - $(stat -c %Y /tmp/Batch-35t-Nearline.LOCK) )) -gt 14400 ];then
54  echo ""
55  echo ".LOCK file is older than 4 hours..."
56  echo "There is a stale lock file that needs attention."
57  echo "Machine: $(hostname)"
58  echo "File: /tmp/Batch-35t-Nearline.LOCK"
59  echo "ProcessNewFiles.sh skipped this file at $(date)."
60  fi
61  echo "lock file /tmp/Batch-35t-Nearline.LOCK exists. Exiting..."
62  echo ""
63  echo ""
64  exit
65 fi
66 
67 touch /tmp/Batch-35t-Nearline.LOCK
68 
69 
70 
71 
72 # Setup necessary pathways:
73 export RelDir=/home/lbnedaq/nearline/nearline_test_release_${version}
74 export ScriptPath=${RelDir}/srcs/dunetpc/dune/NearlineMonitor/scripts
75 export LPDir=${RelDir}/localProducts_larsoft_${version}_${comp}_prof
76 export OutputPath=/lbne/data2/users/lbnedaq/nearline/${version}
77 export OutputSearchPath=/lbne/data2/users/lbnedaq/nearline/v*
78 export BaseFileName=lbne_r
79 export FileSearch='/data/lbnedaq/data/transferred_files/lbne_r*.root'
80 export filepos=6
81 
82 
83 
84 # Only look for new files between 10 min and 60 days old and sort them so that files
85 # with the largest run/subrun numbers are first in the list.
86 for file in $( find ${FileSearch} -mtime -60 -mmin +10 | sort -t "/" -k$filepos -r )
87 do {
88 
89  if [ `ps aux | grep ProcessSingleFile | wc -l` -gt $maxjobs ];then
90  echo ""
91  echo "Reached the max number of running jobs. Exiting..."
92  echo ""
93  echo ""
94  rm -fv /tmp/Batch-35t-Nearline.LOCK
95  exit
96  fi
97 
98  FILE=`basename $file`
99 
100  export bigrun=${FILE:6:3}
101  export run=${FILE:6:6}
102  export subrun=${FILE:15:2}
103  export RunDir=$OutputPath/$bigrun/$run
104  export RunSearchDir=$OutputSearchPath/$bigrun/$run
105 
106  mkdir -p $RunDir
107 
108  num_files=`find $RunSearchDir/${FILE}.DONE 2>/dev/null | wc -l`
109 
110  # Check if this file has already been processed or is curently being processed.
111  if [ $num_files -gt 0 ];then
112  # echo "SKIP: $FILE has already been processed."
113  continue
114  fi
115 
116  num_files=`find $RunSearchDir/${FILE}.LOCK 2>/dev/null | wc -l`
117 
118  if [ $num_files -gt 0 ];then
119  # echo "SKIP: $FILE is currently being processed."
120  continue
121  fi
122 
123  # execute script to process single file
124  echo "Processing $file"
125  cd $ScriptPath
126 
127  # There is too much text output in these jobs. So for now, don't pipe it
128  # to a log file...
129  # nohup ./ProcessSingleFile.sh $RunDir $file $LPDir > $RunDir/$FILE.log 2>&1 &
130  nohup ./ProcessSingleFile.sh $RunDir $file $LPDir >> /dev/null 2>&1 &
131 
132  } done
133 
134 echo ""
135 
136 rm -fv /tmp/Batch-35t-Nearline.LOCK
137 
138 echo ""
139 echo ""