-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_looping.sh
executable file
·82 lines (75 loc) · 1.87 KB
/
bash_looping.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
79
80
81
82
#!/bin/bash
#--------------------------------------------------------------------
# Script to loop through a given range of years
#
# Author: Stefanie Falk
# Date: December 2019
# Update:
#
#--------------------------------------------------------------------
##### Functions
usage()
{
echo "Usage: ./bash_looping [[ -s | --start_year start_year ] [ -e | --end_year end_year][ -o | --output_dir output_directory]]"
}
check_null()
{
if [ $# -eq 0 ]; then
echo "No arguments provided!"
usage
exit 1
fi
}
options()
{
while [ "${1}" != "" ]; do
case $1 in
-s | --start_year )
shift
start_year=${1}
echo "Start year: ${start_year}"
;;
-e | --end_year )
shift
end_year=${1}
echo "End year: ${end_year}"
;;
-o | --output_dir )
shift
output_dir=${1}
echo "output_dir: ${output_dir}"
;;
-h | --help )
usage
exit
;;
* )
usage
exit 1
esac
shift
done
}
cycle_years() {
year=${start_year}
if [[ $start_year > 0 ]]; then
while [ $year -le $end_year ]; do
# Download data from ftp
download_from_ftp $year
# Update counter
year=$(($year + 1))
done
fi
}
download_from_ftp() {
year=$1
echo "Download data for " $year
#wget --ftp-user=nbrown --ftp-password='Stedman5!' ftp://<serveradress to be put>/$year/* ${output_dir}
}
### MAIN
# Check if arguments were provided
check_null $@
# Cycle through options
options $@
# Cycle through years
cycle_years