-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_cmorph2.sh
78 lines (71 loc) · 1.77 KB
/
get_cmorph2.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
71
72
73
74
75
76
77
78
#!/bin/bash
##################################
ddtt=`date +%Y%m%d`
toolDir='/home/processing/ldm-processing-extras'
logDir="$toolDir/log"
(
export PATH=$PATH:/opt/ldm/bin
export PYTHONPATH=/usr/bin/python3
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/python3.6
readonly LOCKFILE_DIR=/tmp
readonly LOCK_FD=201
lock() {
local prefix=$1
local fd=${2:-$LOCK_FD}
local lock_file=$LOCKFILE_DIR/$prefix.lock
# create lock file
eval "exec $fd>$lock_file"
# acquier the lock
flock -n $fd \
&& return 0 \
|| return 1
}
eexit() {
local error_str="$@"
echo $error_str
exit 1
}
main() {
#
echo "+++++ Starting CMORPH2 download - `date` ++++++"
#
# chg to download directory
archiveDir='/mnt/noaa-case-study-data/cmorph2'
cd $toolDir/download
echo "Running: $toolDir/get_cmorph2.py"
$toolDir/get_cmorph2.py
#
if ls | grep CMORPH2
then
for filename in CMORPH2*.nc
do
echo "pqinsert -v $filename"
pqinsert -v $filename
echo "Moving file to $archiveDir"
mv $filename $archiveDir
DFLAG="True"
done
else
echo "No recent files found!"
fi
# clean up old archive files
old_ddtt=`date -d '2 days ago' +%Y%m%d`
echo "Checking for old CMORPH2 files: $old_ddtt"
if ls $archiveDir | grep CMORPH2_0.05deg-30min_"$old_ddtt"
then
echo "Removing CMORPH2 files valid: $old_ddtt"
rm $archiveDir/CMORPH2_0.05deg-30min_"$old_ddtt"*.nc
fi
# also clean up old logs
if ls $toolDir/log | grep cmorph2-"$old_ddtt".log
then
echo "Removing old logs: $old_ddtt"
rm $logDir/cmorph2-"$old_ddtt".log
fi
ddtt=`date +%Y%m%d`
echo "===== End CMORPH2 download - `date` ======"
}
main
#
) >> $logDir/cmorph2-$ddtt".log" 2>&1
#