Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Redirecting stderr from mailx

SOLVED
Go to Solution
Esteemed Contributor Esteemed Contributor

Redirecting stderr from mailx

Within my script, I want to log/catch any errors that mailx may generate - in particular when it is supplied with an invalid recipient.
when I try to just redirect stderr it just seems to ignore it...

> ll | mailx -s "Test e-mail" bert 2> mail.stderr
> bert... User unknown
<$HOME>/dead.letter... Saved message in <$HOME>/dead.letter
>

Where $HOME is the home directory of the user account that I was logged in as.

Any help would be much appreciated.

Thanks,

Gary
1 ACCEPTED SOLUTIONS
Acclaimed Contributor Acclaimed Contributor

Re: Redirecting stderr from mailx

Hi Gary:

# ll | mailx -s "Test e-mail" xxx 1>>/tmp/mylog 2>&1

Regards!

...JRF...
5 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: Redirecting stderr from mailx

Hi Gary:

# ll | mailx -s "Test e-mail" xxx 1>>/tmp/mylog 2>&1

Regards!

...JRF...
Esteemed Contributor Esteemed Contributor

Re: Redirecting stderr from mailx

Hi James,

It's been a long week! I don't know why I didn't redirect stdout as well in the first place.

As a matter of interest, why didn't my original command work?

Have a good week-end.

Thanks,

Gary
Acclaimed Contributor Acclaimed Contributor

Re: Redirecting stderr from mailx

Hi (again) Gary:

> As a matter of interest, why didn't my original command work?

The output messages you really wanted to collect are going to STDOUT not STDERR.

I could have suggested you do:

# # ll | mailx -s "Test e-mail" xxx 1>>/tmp/mylog

...and ignored STDERR entirely.

Regards!

...JRF...
Acclaimed Contributor Acclaimed Contributor

Re: Redirecting stderr from mailx

>why didn't my original command work?

Because your assumptions and the programmer's about what goes to stderr were different.

With an interactive program like mailx, perhaps this is blurred.

Sometimes as JRF had, you should just log both.
Esteemed Contributor Esteemed Contributor

Re: Redirecting stderr from mailx

Thanks for the assistance James.