I'm trying to intercept stdin in a script, before it gets piped to other commands, send this stdin to a file and have the original stdin piped further.
To clarify, see my situation: the script right now reads like this:
Code:
/usr/local/bin/faxmail -n | /usr/local/bin/sendfax -n -D -R -A -P high -f "$2" -d "$1"
faxmail takes a raw e-mail message from stdin, converts it to postscript and pipes it over to sendfax. I want to write the raw e-mail to a file, for debugging reasons.
I've tried it this way:
Code:
mytmp="/tmp/testfax$$"
while read x
do
echo $x >> $mytmp
done
cat $mytmp | /usr/local/bin/faxmail -n | /usr/local/bin/sendfax -n -D -R -A -P high -f "$2" -d "$1"
The problem is that the headers of the e-mail have idented lines and if I echo them, the indentation gets lost. I really need everything to be exactly as it came from stdin.
Also, I don't want to intercept my file between faxmail and sendfax, because the output of faxmail is already a postscript document.
Anyone can help me here?