Hi Viktor,

I though I new a little of bash but in fact no ... you're a bash king !

if I understood it well :
first, I save the message in the file descriptor 3

    msg=$(mktemp /tmp/msg.XXXXXX) || exit 75
    cat > $msg || { rm $msg; exit 75; }
    exec 3< $msg || { rm $msg; exit 75; }
    rm $msg

then I use it by rewinding it :

        perl -e 'open IN, "<&", 3; seek(IN, 0, 0);'

is there a way to rewind without using perl ?
I try to stay as close as possible of pure bash ... id not I'd rather switch 
directly in perl but that sound like a lost time to rebuild everything in perl 
where the bash is working for 95% of the task, I just miss the forward as email 
of some messages.


thanks for your time and patience
Stéphane !

Le 21/12/2016 à 19:39, Viktor Dukhovni a écrit :
On Wed, Dec 21, 2016 at 05:00:19PM +0100, Stéphane MERLE wrote:

lemail=$(cat)
Instead of buffering the message into a shell variable, buffer it
into a temporary file (and set a "trap" command to delete the file).

You can then inspect the file content before sending the right
message.

It is possible to pre-unlink the file, while keeping an open handle:

     msg=$(mktemp /tmp/msg.XXXXXX) || exit 75
     cat > $msg || { rm $msg; exit 75; }
     exec 3< $msg || { rm $msg; exit 75; }
     rm $msg

You can then read the file multiple times by rewinding file descriptor 3:

     perl -e 'open IN, "<&", 3; seek(IN, 0, 0);'
     if grep 'pattern' <& 3 >/dev/null; then
        set -- "$@" "$additional_recipient"
     fi

And finally

     perl -e 'open IN, "<&", 3; seek(IN, 0, 0);'
     exec sendmail -i "$@" <&3


Reply via email to