-
Notifications
You must be signed in to change notification settings - Fork 0
/
1033.sh
executable file
·35 lines (30 loc) · 1.09 KB
/
1033.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
#!/bin/bash
# find file name
FILE=$(wget -O - https://www.dla.mil/DispositionServices/Offers/Reutilization/LawEnforcement/PublicInformation/ \
| grep -o "AllStatesAndTerritories.*\.xlsx")
# download to temporary file
wget -O temp.xlsx "https://www.dla.mil/Portals/104/Documents/DispositionServices/LESO/$FILE"
DATE=$(date +"%m-%d-%y")
export DATA="${DATE}-${FILE}"
export DATA_DIR=$(pwd)
# check if first time running
SHEETS=$(ls -1 *.xlsx 2>/dev/null | wc -l)
if [ $SHEETS = 1 ]; then
mv temp.xlsx $DATA
echo "${DATE}: 1033 data downloaded" > log
Rscript 1033.R "${DATA}"
else
# get sha256 of most recent local file and compare with downloaded file
NEWEST=$(ls -1t *.xlsx | awk 'NR==2')
NEW_SHA=$(sha256sum temp.xlsx | cut -d " " -f1)
OLD_SHA=$(sha256sum $NEWEST | cut -d " " -f1)
# rename and save file if newer than most recent local one
if [ $OLD_SHA != $NEW_SHA ]; then
mv temp.xlsx $DATA
echo "${DATE}: new 1033 data downloaded" >> log
Rscript 1033.R "${DATA}"
else
rm temp.xlsx
echo `date +"%m-%d-%y"`": no new 1033 data downloaded" >> log
fi
fi