Script to identify the files based on current date and file name pattern
In your find
command you can drop the single-quotes around the date
variable as
find -type f -name "*_${date}*.csv"
since the double-quotes "
as such expand the value of variables in bash
and you don't have to single quote again.
Demo:-
touch abc_2016-12-28-3523424-acsfsc.csvtouch abc_2016-12-29-3523424-acsfsc.csv
Confirming once the presence of the files without the -name
filter
find . -maxdepth 1 -type f -print./abc_2016-12-28-3523424-acsfsc.csv./abc_2016-12-29-3523424-acsfsc.csv
Now setting the variable date
to today's date as
date=$(date +%Y-%m-%d)find -type f -name "*_${date}*.csv"./abc_2016-12-28-3523424-acsfsc.csv
Also do not use pipe-line to set variables in bash
, use process-substitution and use -print0
for a more robust handling of files with special characters in the filenames.
while IFS='' read -r -d '' filenamedo echo "filename : ${filename}" var=$(base64 "$filename"| perl -pe 's/\n//g'); var1=$(curl -XPUT "http://localhost:9200/documents-$date/document/?pipeline=attachment&pretty" -d '{ "data" : "'"$var"'" }')done < <(find -type f -name "*_${date}*.csv" -print0)