Email attachment created in bash script with uuencode and ssmtp is delivered with malformed filename and zero-length
0
votes
2
answers
81
views
This very old thread shows how to use uuencode and ssmtp to send an email with attachment from a bash script.
I've created this test script to debug:
#!/bin/bash
set -x
NOW=$( date '+%F' ) #( date '+%F_%H-%M-%S' )
LOGPATH=/home/pi/logs
LOGFILE=test-log-$NOW.txt
FULL_LOG=$LOGPATH'/'$LOGFILE
echo "This is a test of the log email send $LOGPATH $LOGFILE $FULL_LOG " > $FULL_LOG
echo -e "To: test@mydomain.com\nSubject: test log send\n\n" | (cat - && /usr/bin/uuencode $FULL_LOG) | /usr/sbin/ssmtp -t
Output looks like this:
+ echo 'This is a test of the log email send /home/pi/logs test-log-2025-02-22.txt /home/pi/logs/test-log-2025-02-22.txt '
+ echo -e 'To: test@mydomain.com\nSubject: test log send\n\n'
+ cat -
+ /usr/sbin/ssmtp -t
+ /usr/bin/uuencode /home/pi/logs/test-log-2025-02-22.txt
No errors occur, and an email is delivered with the subject to the correct address.
The problem is the email attachment is delivered as a file named
homepilogstest-log-2025-02-222.txt
The attachment is a zero-length file. The file is correctly created on the Pi and contains the expected contents:
$ ls -l logs/test-log-2025-02-22.txt
-rw-r--r-- 1 pi pi 116 Feb 22 12:19 logs/test-log-2025-02-22.txt
$ cat logs/test-log-2025-02-22.txt
This is a test of the log email send /home/pi/logs test-log-2025-02-22.txt /home/pi/logs/test-log-2025-02-22.txt
What am I missing?
Asked by tim11g
(115 rep)
Feb 22, 2025, 06:33 PM
Last activity: Feb 25, 2025, 01:40 PM
Last activity: Feb 25, 2025, 01:40 PM