-
Notifications
You must be signed in to change notification settings - Fork 0
/
snodas_daily_update.sh
60 lines (51 loc) · 1.53 KB
/
snodas_daily_update.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
#! /bin/bash
# script to be run daily (cron job) to obtain the latest SNODAS grids. Note that the
# snodas grids seem to come online at 7 am each day. So, I will set the cron job to run
# this at noon each day, and grab that day's files
# david hill, oregon state university, [email protected], 17 jun 2020
#establish home directory for where my snodas archive is already at
homedir="/nfs/attic/dfh/data/snodas/snodas_download"
echo "$homedir"
#create folder for temp download
tempdir="$homedir/dailyupdate"
echo "$tempdir"
mkdir -p $tempdir
cd $tempdir
#get today's date info
day=$(date '+%d')
month=$(date '+%b')
monthnum=$(date '+%m')
year=$(date '+%Y')
#build up filename to get (Hs)
filename="SNODAS_$year$monthnum$day.tar"
#get file
wget -N ftp://sidads.colorado.edu/DATASETS/NOAA/G02158/masked/$year/"${monthnum}_${month}"/$filename
#untar
tar -xvf $filename
#clean up by removing .tar file
rm $filename
#unzip
gunzip -f *.gz
#create destination folders for 1034 (SWE) and 1036 (HS) files.
mkdir -p "../$year/${monthnum}_${month}/Hs"
mkdir -p "../$year/${monthnum}_${month}/SWE"
#move 1034 files to SWE folder and 1036 files to Hs
#folder...the rest will be deleted. Easy to change this to keep additional
#variables of interest (1025SlL00, 1025SlL01, 1038, 1039, 1044, 1050)
FILES=*.*
for files in $FILES
do
case $files in
*1034*)
mv $files "../$year/${monthnum}_${month}/SWE/."
;;
*1036*)
mv $files "../$year/${monthnum}_${month}/Hs/."
;;
esac
done
#remove the other files
rm *.*
#remove the temporary directory
cd ..
rmdir $tempdir