Read pipe data

Hello,

I need to read the pipe data as:-

cat abc.txt | uuencode abc.txt | mailx -s hi xyz@xyz.com

I will override the mailx function so that when mailx is called, it calls my version of maix and in that function I want to read the file which is attached in progional mailx function- abc.txt

Once done, I can do whatever I want with this data...sending it to somebody else rather to intended receipient....

Is there any way to it?

Thanks

Why do you need to override mailx instead of just sending mail to the correct people in the first place, or altering sendmail's settings to do what you want?

In the project I am working for, the requirement is that, the mails should not go to intended users if we are on Non Production server.

We dont want to change the codes where email addresses are hard coded or are taken from external files.

Something to handle at run time...

I think it would make sense to change your mail server than your code. Otherwise it's not really been tested.

"intercepting" a command is going to be very awkward at best.

I suppose you could have a MAILX variable, and use $MAILX instead of mailx for your mail command, and alter the variable when your program begins depending on the hostname.

Ok, thanks for the suggestion.

Please let me know, what needs to be done in order to handle it via changing the mail server?

What's your mail server?

I am not sure of it as of now...have not digged into it and have little knowledge about it. All I know is, it is somewhere defined in /etc/mail folder.

The codes that I need to handle use mailx or sendmail commands to send mail.

Please let me know further on it.

Thanks

If you don't know what your mailserver is, I suppose it wouldn't be a good idea to fiddle with it. Unfortunate.

I guess I'd go with something like this instead:

mysendmail() {
        # ignore parameters, do as we please
        sendmail ...
}

mymailx() {
        # Ignore parameters, do as we please
        mailx ...
}

MAILX="mailx"
SENDMAIL="sendmail"


if [ $HOSTNAME = "debugserver" ]
then
        MAILX="mymailx"
        SENDMAIL="mysendmail"
fi

...

echo $MESSAGE | $SENDMAIL username@host

I don't like it, since it means the actual mailing code doesn't get tested, and your code ends up with hardcoded hostnames in it.