Trying to use the "find" command to list of files and send as a list instead of a one line list.
expecting outcome on body of the email listing the files (see bodyHTML line as well):
file1
file2
file3
current outcome:
"file1,file2,file3" <--not want I want on the body of the email.
FOLDER="/temp"
FILES="$(sudo find $FOLDER/*.txt -cmin -60 -type f)"
FILES_COUNT=$($FILES | wc -l)
EMAIL_TO="###"
FROM_EMAIL="###"
FROM_NAME="TEST"
SUBJECT="TEST"
TODATE=$(date "+ %D %T")
bodyHTML="<div><H2 style='color:grey;'>$FILES_COUNT Total new files on $TODATE</H2><Table border=1 cellpadding=5 cellspacing=0><TR bgcolor=white align=left><TD><B>$FILES</B></TD></TR>"
maildata='{"personalizations": [{"to": [{"email": "'${EMAIL_TO}'"}]}],"from": {"email": "'${FROM_EMAIL}'",
"name": "'${FROM_NAME}'"},"subject": "'${SUBJECT}'","content": [{"type": "text/html", "value": "'$bodyHTML'"}]}'
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header 'Authorization: Bearer '$SENDGRID_API_KEY \
--header 'Content-Type: application/json' \
--data "'$maildata'"
When I use:
FILES="$(sudo find $FOLDER/*.txt -cmin -60 -type f)"
echo $FILES
outcome:
/temp/test.txt /temp/tes2.txt /temp/test3.txt /temp/test4.txt /temp/test5.txt
When I don't use echo before $FILES:
$FILES
outcome:
Endless loop of the follow below:
"/temp/test1.txt: line 88: +oAtMghU1YTaI+6doyj1Z7cALL5ATHPmrxLQweNYFv2S7WuIryTq9k+LaiQnDo9/: No such file or directory"