-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathjob.sh
52 lines (41 loc) · 1.2 KB
/
job.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
#!/bin/bash
function usage
{
echo "usage: job [[-pm] | [-h]]"
echo "Parameters:"
echo "-pm | --previous-month = process the previous month from current date"
}
BUCKET='s3://bucket-123456'
ACCOUNT='123456789012'
YEAR=$(date +%Y)
MONTH=$(date +%m)
LOCAL_FOLDER='/mnt/jobs'
ES_HOST='elastic-search-host.endopoint.name'
ES_PORT=80
# Process input parameters
while [ "$1" != "" ]; do
case $1 in
-pm | --previous-month )echo "Processing previous month!"
MONTH=$(date --date='-1 month' +%m)
YEAR=$(date --date='-1 month' +%Y)
;;
-h | --help ) usage
exit
;;
esac
shift
done
DBR_FILE=$ACCOUNT-aws-billing-detailed-line-items-with-resources-and-tags-$YEAR-$MONTH.csv
ZIP_FILE=$DBR_FILE.zip
#Change to local working folder
cd $LOCAL_FOLDER
# Copy the file from bucket to local folder
aws s3 cp $BUCKET/$ZIP_FILE .
# Extract the ziped file
unzip -o $ZIP_FILE
# Process the file with dbrparser
dbrparser -i $DBR_FILE -e $ES_HOST -p $ES_PORT -t 2 -bm 2 -y $YEAR -m $MONTH --delete-index -bi
# Remove processed file
rm $DBR_FILE
rm $ZIP_FILE
echo 'Finished processing...'