I want to add current date to the file name. when sending an email with attachment.

My script:


now=`date +"%m_%d_%Y"`

mutt -s "Reports $now" someone@gmail.com -a /path/Reports.xlsx < /path/mailmessage.txt

However, I want the current date with filename instead in email subject. As the file is modified daily and sent out through email.

eg: Reports_08032017.xlsx when received in email.

Is it possible?

Any help is appreciated.


Create a temporary copy with desired filename which you can delete after sending the mail.

NOW=$(date +'%m_%d_%Y')

cp "/path/Reports.xlsx" "$TMPCOPY"
mutt -s "Reports $NOW" someone@gmail.com -a "$TMPCOPY" < /path/mailmessage.txt

  • Thanks, should I create a /tmp/ folder for TMPCOPY? – Chid Aug 3 '17 at 17:59
  • You can use any folder you prefer to. /tmp is for storing temporary files and it should exist on basically any linux system. – sebasth Aug 3 '17 at 18:05

It's probably best to do when the file is created but you can also change the name of it like this:

today=$(date +%m-%d-%Y)
mv $file $nfile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.