You are not logged in.
I have setup msmtp and smartd, notifcations are being mailed - so that part works.
In addition I would like smartctl output of each disk to be mailed on a regular basis, I created a simple script that I would like to schedule with cron:
#!/bin/bash
for DISK in $(ls -b /dev/disk/by-id/{ata*,nvme*}|grep -v -E 'part|eu|_1'); do
SMARTD_MESSAGE="$(smartctl -a ${DISK})"
printf '%s\n' "Subject: hostname - ${DISK}"\\n"${SMARTD_MESSAGE}" | msmtp -a mailprovider notifications@maydomain.net
done
I added the '%s' because the smartctl output contains % signs and would otherwise throw an error there are invalid characters.
The mails end up in my sent mail folder with no recipient (did not send). The subject contains the first line of the smartctl output which is supposed to go into the body, separated with the character 'n' from '\n'.
I tried a couple of things with different quotes and adding '\n' to the '%s' but I can't make it work. I either get errors or no recipient with malformed subject.
Anyone an idea how I can make this work?
Thanks!
Last edited by mouseman (2023-07-17 06:06:08)
Offline
I solved it by using the mail command instead of msmtp as follows:
echo "${SMARTD_MESSAGE}" | mail -s "Hostname disk - ${disk}" notifications@mydomain.net
Offline