2

I have a script that currently does:

cat $body | uuencode $attachment $attachment | sendmail $sender -t

What should I adjust so that $attachment could be multiple attachments? I have come up with the below but it doesn't look correct?

cat $body |
for i in $attachments 
do
uuencode $i $i
done
| sendmail $sender -t
user2656114
  • 949
  • 4
  • 18
  • 35

3 Answers3

0

Typically, you don't want to store a list of file names in a parameter. With default IFS, spaces embedded within file names will give rise to problems. Instead, declare an array with files

a=(file1 file2 file3 file4)
(for file in "${a[@]}"; do uuencode "$file" "$(basename "$file")"; done) |
 sendmail $sender -t
iruvar
  • 22,736
  • 7
  • 53
  • 82
  • @user2656114, i was assuming you were looking to uuencode and send multiple attachments. Are you trying to chop one file into many and send each part as a separate attachment? – iruvar Nov 12 '13 at 21:42
  • No each attachment listed in $attachments needs to be added. – user2656114 Nov 12 '13 at 22:37
  • @user2656114, see if my latest works for you. You could declare an array comprising all the files within `$attachments` and try the above – iruvar Nov 12 '13 at 22:39
0

Try the following script:

# specify list of email recipients
recipients=...
# specify envelope sender address
sender=...
( 
  cat $body
  for i in $attachments 
  do
    uuencode $i $i
  done
) | sendmail -f$sender -i -- $recipients
  • $body file must contain message headers (e.g. Subject:) separated by an empty line from message body
  • IMHO it is a better/safer style to specify recipients via command line instead of making sendmail extract them from headers.
AnFi
  • 10,493
  • 3
  • 23
  • 47
0

FILES="/rollovers/DailyCadRpt.* /rollovers/DailyFireRpt.*"

(for f in $FILES ; do uuencode "$f" "$f" ; done ) | mail -s "Subject" recipient_email@domain.com

The above works in AIX 6.1 for wildcards. But, you must use the 10-pad asterisk. The asterisk above the number eight does not work in AIX. Also, this does not have any body text. But that is done as in the other examples. You may add more files by using a space as the separator, as in my example. Also, you cannot use Daily* with either asterisk. AIX just won't do it. The asterisk must come after a period in the file name. Our reports have the date added to the report name separated by a period. It preserves our archival naming pattern and grabs it every day without needing a specific file name.

Dan
  • 1