Redirecting stderr from mailx (162 Views)
Reply
Esteemed Contributor
Gary Cooper_1
Posts: 657
Registered: ‎04-04-2002
Message 1 of 6 (162 Views)
Accepted Solution

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
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 6 (162 Views)

Re: Redirecting stderr from mailx

Hi Gary:

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

Regards!

...JRF...
Esteemed Contributor
Gary Cooper_1
Posts: 657
Registered: ‎04-04-2002
Message 3 of 6 (162 Views)

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
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 6 (162 Views)

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
Dennis Handly
Posts: 25,277
Registered: ‎03-06-2006
Message 5 of 6 (162 Views)

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
Gary Cooper_1
Posts: 657
Registered: ‎04-04-2002
Message 6 of 6 (162 Views)

Re: Redirecting stderr from mailx

Thanks for the assistance James.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.