0

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

My script:

#!/bin/sh
clear

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.

2

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

NOW=$(date +'%m_%d_%Y')
TMPCOPY="/tmp/Reports_$NOW.xlsx"

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

rm "$TMPCOPY"
  • 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
0

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)
file="/path/Reports.xlsx"
nfile="/path/Reports-$today.xlsx"
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.