0

I have a problem. I need to write a script that will find any file generated 1 day ago And then email it to certain mail-address from Tuesday to Sunday at 2 am?

The problem is my script finds the 3 correct files but either sends 3 different emails with single attachment or send 1 email without any attachment. How can I edit it to send multiple attachments in 1 email? It seems every file needs a 'uuencode' with it, so tried concating "uuencode" to the "filename" and then add that variable to the command of ssmpt. Neither of the 2 version are really working.

How can I write the regular experession so that all the files found is emailed using 1 email. My current script just sends email with no attachment at all or 1 file per email.

Please help.

Here is what my script looks like:

Version 1: sends 1 email with no attachment:

#!/bin/bash dt=$(date --date yesterday "+%Y-%m-%d") result="performance-team*-$dt.txt" arr=() arr=($(find /root/Desktop/fileNAme -type f -name "${result}")) for i in "${arr[@]}" do value=" uuencode -e $i $(basename $i);" valueTotal=$valueTotal$value; done echo -e "to:[email protected]\nSubject:performance of teams on ${dt};"|(cat - && ${valueTotal};)|/usr/sbin/ssmtp [email protected]

Version 2: sends 3 email with single attachment in each:

#!/bin/bash dt=$(date --date yesterday "+%Y-%m-%d") result="performance-team*-$dt.txt" arr=() arr=($(find /root/Desktop/fileNAme -type f -name "${result}")) Count=0 for i in "${arr[@]}" do Count=$((Count+1)) echo -e "to:[email protected]\nSubject:performance of teams on ${dt}; mail ${Count} of 3\n"|(cat - && uuencode $i;)|/usr/sbin/ssmtp to:[email protected] done 
2
  • How about using tar to combine the files you find, and then uuencode the resulting tarfile?
    – MikeA
    CommentedOct 18, 2016 at 19:36
  • Or is mutt available?
    – thrig
    CommentedOct 18, 2016 at 20:12

1 Answer 1

1

uuencode is the wrong tool for the job. (It was the right tool about 25 years ago, though, but has long been superseded by the MIME standard.)

On my Debian distribution a script can use the mail command directly. The man page for mail says, amongst other things, "-a file Attach the given file to the message". Here is an example that sends three attachments encoded using MIME.

echo 'Here is my email' | mail -s 'Test message' -a /etc/hosts -a /etc/group -a /etc/motd [email protected]

I have not had time to check this next part, but it looks like munpack may be the tool to perform the reverse conversion, i.e. extract MIME attachments from an email back into files.

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.