I'm creating a script to rotate my backups, one important part of this script is to find the files based on certain criteria and then move them or erase them.
I've got the loop going, but the Array (path_array), can't be used outside the loop. I've read several posts about this, but not sure how the answers apply to my specific case. See code below.
Thanks!!!
#!/bin/bashanos=(2016 2017 2018 2019)
meses=(02)
meses=(01 02 03 04 05 06 07 08 09 10 11 12)
anos=(2018)source=“/volume1/NetBackup/Servers/MIA/”
destination=“/volume1/NetBackup/Servers/MIA/_Archive”######## Pasar los Files del Primer dia del Año a Archiving
for i in ${anos[@]}; do
for j in ${meses[@]}; do
month_start=$(date +$i-$j-01)
month_finish=$(date +$i-$j-02)
# echo $month_start
# echo $month_finish
path_array=(find $source -type f -not -path "*/_Archive/*" -newermt $month_start ! -newermt $month_finish | cut -sd / -f 6-
)
# echo $path_array# echo Archivos año: $i mes: $j #printf '%s\n' "${path_array[@]}" done
done
printf ‘%s\n’ “${path_array[@]}”
#bash #arrays #loops