Mail attachment from Unix script in loop
Mail attachment from Unix script in loop
I have below sample script which was working fine until last week, however, not sure what has changed, I am not getting any attachments sent. I just get greet / text message but not any attachment. I tried with sample .txt as attachment which is success. But not .csv, not sure if csv's are being filtered by unix server, but I don't see any error message. Any idea how to track / check what is going wrong pls?
#!/bin/bash
FILES=/inbox/*.*
to="test@temp.com"
from="test@temp.com"
subject="Test Files"
filecount=`find $FILES -type f | wc -l`
totalfiles=" : Total "
subject=${subject}${totalfiles}${filecount}
body="Dear All,Please find the attached latest files."
echo $subject $filecount
declare -a attargs
for att in $(find $FILES -type f -name "*.*");do
#attaching all files.
attargs+=( "-a" "$att" )
done
mail -s "$subject" -r "$from" "${attargs[@]}" "$to" <<< "$body"**
Kind Regards
Kevin
subject="..."
echo $subject $filecount
FILES=/inbox/*.*
find
*.*
FILES
-name
thanks you for comments , yes above code was added to check what is going wrong, but didn't actually fixed issue.
– Kev
Jul 3 at 7:27
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
1, need quotes around
subject="..."
. 2,echo $subject $filecount
will be redundant since filecount is already assigned in subject. 3,FILES=/inbox/*.*
but it's never used anywhere except as afind
target, so you don't need the*.*
both inFILES
and the-name
argument to find. (unless there are files that don't meet the . spec, you don't need it at all.) I doubt any of thise will fix your problem, but cleaning up is usually a good place to start.– Paul Hodges
Jul 2 at 18:31