'Bash: Mailing output from continuosly running command

I got a broker running. It is possible to subscribe to a channel of that broker in order to receive messages that have been published to a channel on this broker. My objective is to send each received message as email.

My simplyfied command to subscribe to my brooker looks like to this:

brooker subscribe --host myhost -i user -c mychannel

When called from command line i receive messages when they are published as console output (the script keeps running!). The difficulty lies in capturing the output of my command and feeding it to a mail command.

So far I tried to put the following simplified line into my bash script:

brooker subscribe --host myhost -i user -c mychannel | mail -s "alert" [email protected]

The mailing part has been tested and is functional. But i do not receive any emails at all when i run my script and publish messages in second console to a channel of the broker.

Question: How can i feed the continuosly incoming messages to my mail command.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source