V
V
VN2021-04-29 15:51:14
bash
VN, 2021-04-29 15:51:14

How to set up sending mail with an attachment, where the name of the attachment always changes?

Please tell me how to implement.

I have a script that sends a message with an attachment

#!/bin/bash
for I in `cat list_adresses`; do cat body | mutt -e "set content_type=text/html" -a 
"/path/to/directory/File_name_29.04.21" -s "Тема письма" -- $I < body;echo $I;sleep 1 ;done

The whole thing is that the file name always changes, namely the date in the file name changes. Today _29.04.21, tomorrow _30.04.21.

How to set up an attachment so that the script makes attachments based on the first part of the file name -- File_name

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VN, 2021-04-29
@kavabangaungava

In general, it's very simple to
make a variable
attach=$(ls /path/to/file/ | grep File_name)
AND put the variable in the attachment
-a "/path/to/file/$attach"

D
Dmitry, 2021-04-29
@q2digger

if the date changes in a predictable way, i.e. it always matches "today", then use the date.
File_name_`date +%d.%m.%y`"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question