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....
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?
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.
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.
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.