1- #! /bin/bash
1+ #! /usr/ bin/env bash
22echo " Executing the download_data.sh script"
33
44# === Description ===
@@ -10,19 +10,37 @@ DEST_DIR="$HOME/work/data"
1010# Ensure destination folder exists
1111mkdir -p " $DEST_DIR "
1212
13- # === Download a first file ===
14- DATA_PATH=" s3/donnees-insee/diffusion/ETAT_CIVIL/2020/DECES_COM_1019.csv"
15- echo " Downloading $DATA_PATH to $DEST_FILE ..."
16- mc cp " $DATA_PATH " " $DEST_DIR "
13+ # === Download all data files ===
14+ # You can modify the list of files
15+ FILES=(
16+ " s3/donnees-insee/diffusion/ETAT_CIVIL/2020/DECES_COM_1019.csv"
17+ " s3/donnees-insee/diffusion/ETAT_CIVIL/2020/NAISSANCES_COM_1019.csv"
18+ )
1719
18- # === Check success ===
19- if [ $? -eq 0 ]; then
20- echo " ✅ File downloaded successfully to $DEST_FILE "
21- else
22- echo " ❌ Failed to download file from $DATA_PATH "
23- exit 1
24- fi
20+ # Function to download with retry
21+ download_file () {
22+ local file=$1
23+ local dest=$2
24+ local retries=3
25+ local count=0
2526
26- # === Download a second file ===
27- # Repeat the code above for each file
27+ while [ $count -lt $retries ]; do
28+ echo " Attempt $(( count+ 1 )) to download $file ..."
29+ if mc cp " $file " " $dest " ; then
30+ echo " Download of $file succeeded."
31+ return 0
32+ else
33+ echo " Download failed for $file . Retrying..."
34+ (( count++ ))
35+ sleep 2
36+ fi
37+ done
38+ echo " Failed to download $file after $retries attempts."
39+ return 1
40+ }
2841
42+ # Iterate and download each file
43+ for FILE in " ${FILES[@]} " ; do
44+ echo " Downloading $FILE to $DEST_DIR ..."
45+ download_file " $FILE " " $DEST_DIR "
46+ done
0 commit comments