Sending file as attachment using mailx command

202 views Asked by At

I have few xlsx files with different timestamps. I have mentioned sample files for reference.

abt_rpt_20221216_0137.xlsx
abt_rpt_20221216_0136.xlsx

I want only the first file (with latest timestamp) as an attachment via email. Since the file size is huge, I'm trying to zip the file and email the file(which has latest timestamp as an attachment). Looks like I'm making error in my script.

The email shoould contain the attachment of a single .xlsx file which has the latest timestamp.

#!/bin/bash
dt=$(date +"%Y%m%d_%H%M")
cd /dev/abd_dev/alb/test/Scripts/albt/at

zip -r /dev/abd_dev/alb/test/Scripts/albt/at/report.zip /dev/abd_dev/alb/test/Scripts/albt/at/*.xlsx | head -1


# Sending Email

for file in *.zip ; do
  [[ -f "${file}" ]] || continue
    attachments+=( "-a" "${file}" )
done

echo "Hi,
      File Attached"| mailx -s "Test" "${attachments[@]}" "[email protected]"

Need to understand what I'm doing wrong. Can anyone guide me on this?

0

There are 0 answers