You are not logged in.

#1 2023-07-16 11:53:00

mouseman
Member
From: Outta nowhere
Registered: 2014-04-04
Posts: 291

[solved] prinft pipe send mails escaping issue

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

#2 2023-07-17 06:05:52

mouseman
Member
From: Outta nowhere
Registered: 2014-04-04
Posts: 291

Re: [solved] prinft pipe send mails escaping issue

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

Board footer

Powered by FluxBB