-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_calibrate_zdr.sh
executable file
·70 lines (51 loc) · 1.99 KB
/
run_calibrate_zdr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# This file runs the calibrate_zdr.py script over several paths
# Se the directory to look for the files
dir=/automount/realpep/upload/jgiles/dmi/
# Which location to process
loc=HTY
# Set the type of calibration method
calibtype=3
max_attempts=5 # Maximum number of restart attempts
max_execution_time=700 # Maximum execution time in seconds
# Create a list of all files that include *allmoms* in their name
files=$(find $dir -name "*allmoms*$loc*" -type f -not -path "*qvp*" -not -path "*WIND*" -not -path "*SURVEILLANCE*" -not -path "*RHI1*")
# Loop through each file in the list
for file in $files; do
attempt=1
while [ $attempt -le $max_attempts ]; do
# Invoke the Python script with the file path as an argument
python /home/jgiles/Scripts/python/radar_processing_scripts/calibrate_zdr.py $file $calibtype &
# Get the process ID of the background script
script_pid=$!
# set time counter and steps
timecount=0
sleepterval=5
while [ $timecount -le $max_execution_time ]; do
# sleep for a bit
sleep $sleepterval
timecount=$(( $timecount + $sleepterval ))
# Check if the script is still running
if ps -p $script_pid > /dev/null; then
: # do nothing
else
# Script finished successfully, break out of the loops
break 2
fi
done
# if after the max time the script is still running, kill it
kill $script_pid
echo "Script exceeded time limit. Killing and retrying..."
# clean the created folder
newfolder="${file/${dir}/${dir}rhohv_nc/}"
newfolder=$(dirname "$newfolder")
if [ -d "$newfolder" ]; then
rm -r "$newfolder" # clean the created folder
fi
((attempt++))
done
if [ $attempt -gt $max_attempts ]; then
echo "Max restart attempts reached, could not be completed: $new_path"
fi
done
wait