Hi All,
I still get all the trash with this:
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To 2>&1 > /dev/nul
I think I am putting the `2>&1 > /dev/nul` in the wrong place.
What am I doing wrong?
Many thanks, -T
On Sat, 2025-05-24 at 04:47 -0700, ToddAndMargo via users wrote:
Hi All,
I still get all the trash with this:
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To 2>&1 > /dev/nul
I think I am putting the `2>&1 > /dev/nul` in the wrong place.
What am I doing wrong?
It's the wrong way round. The 2>&1 means "redirect the current fd 2 to the same place as fd 1", but at this point fd 1 is still unchanged. You also misspelled /dev/null but I assume that's a typo.
You want "... > /dev/null 2>&1".
poc
On 5/24/25 4:56 AM, Patrick O'Callaghan wrote:
On Sat, 2025-05-24 at 04:47 -0700, ToddAndMargo via users wrote:
Hi All,
I still get all the trash with this:
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To 2>&1 > /dev/nul
I think I am putting the `2>&1 > /dev/nul` in the wrong place.
What am I doing wrong?
It's the wrong way round. The 2>&1 means "redirect the current fd 2 to the same place as fd 1", but at this point fd 1 is still unchanged. You also misspelled /dev/null but I assume that's a typo.
You want "... > /dev/null 2>&1".
poc
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To > /dev/null 2>&1
Mailx hangs. I think mailx thinks it is a parameter.
On 5/24/25 5:10 AM, ToddAndMargo via users wrote:
On 5/24/25 4:56 AM, Patrick O'Callaghan wrote:
On Sat, 2025-05-24 at 04:47 -0700, ToddAndMargo via users wrote:
Hi All,
I still get all the trash with this:
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To 2>&1 > /dev/nul
I think I am putting the `2>&1 > /dev/nul` in the wrong place.
What am I doing wrong?
It's the wrong way round. The 2>&1 means "redirect the current fd 2 to the same place as fd 1", but at this point fd 1 is still unchanged. You also misspelled /dev/null but I assume that's a typo.
You want "... > /dev/null 2>&1".
poc
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To > / dev/null 2>&1
Mailx hangs. I think mailx thinks it is a parameter.
I lost contact with the server. Something is amiss.
On Sat, 2025-05-24 at 05:10 -0700, ToddAndMargo via users wrote:
On 5/24/25 4:56 AM, Patrick O'Callaghan wrote:
On Sat, 2025-05-24 at 04:47 -0700, ToddAndMargo via users wrote:
Hi All,
I still get all the trash with this:
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To 2>&1 > /dev/nul
I think I am putting the `2>&1 > /dev/nul` in the wrong place.
What am I doing wrong?
It's the wrong way round. The 2>&1 means "redirect the current fd 2 to the same place as fd 1", but at this point fd 1 is still unchanged. You also misspelled /dev/null but I assume that's a typo.
You want "... > /dev/null 2>&1".
poc
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To > /dev/null 2>&1
Mailx hangs. I think mailx thinks it is a parameter.
You didn't say what the problem was in your original post so I looked no farther than the "2>&1" thing. I suggest running the whole script under 'sh -x' to see what it's actually doing.
I would also run it through shellcheck to catch any obvious bloopers in the syntax. I wou;d also enclose everything after the '|' in parentheses so it executes in a subshell, in case the redirections aren't doing what you think.
poc
On 5/24/25 5:15 AM, ToddAndMargo via users wrote:
On 5/24/25 5:10 AM, ToddAndMargo via users wrote:
On 5/24/25 4:56 AM, Patrick O'Callaghan wrote:
On Sat, 2025-05-24 at 04:47 -0700, ToddAndMargo via users wrote:
Hi All,
I still get all the trash with this:
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To 2>&1 > /dev/nul
I think I am putting the `2>&1 > /dev/nul` in the wrong place.
What am I doing wrong?
It's the wrong way round. The 2>&1 means "redirect the current fd 2 to the same place as fd 1", but at this point fd 1 is still unchanged. You also misspelled /dev/null but I assume that's a typo.
You want "... > /dev/null 2>&1".
poc
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To
/ dev/null 2>&1
Mailx hangs. I think mailx thinks it is a parameter.
I lost contact with the server. Something is amiss.
I set it up on my computer.
I still get the trash
On 5/24/25 6:00 AM, ToddAndMargo via users wrote:
On 5/24/25 5:15 AM, ToddAndMargo via users wrote:
On 5/24/25 5:10 AM, ToddAndMargo via users wrote:
On 5/24/25 4:56 AM, Patrick O'Callaghan wrote:
On Sat, 2025-05-24 at 04:47 -0700, ToddAndMargo via users wrote:
Hi All,
I still get all the trash with this:
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To 2>&1 > /dev/nul
I think I am putting the `2>&1 > /dev/nul` in the wrong place.
What am I doing wrong?
It's the wrong way round. The 2>&1 means "redirect the current fd 2 to the same place as fd 1", but at this point fd 1 is still unchanged. You also misspelled /dev/null but I assume that's a typo.
You want "... > /dev/null 2>&1".
poc
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To
/ dev/null 2>&1
Mailx hangs. I think mailx thinks it is a parameter.
I lost contact with the server. Something is amiss.
I set it up on my computer.
I still get the trash
This worked: ... > /dev/null 2>&1
On 5/24/25 6:02 AM, ToddAndMargo via users wrote:
On 5/24/25 6:00 AM, ToddAndMargo via users wrote:
On 5/24/25 5:15 AM, ToddAndMargo via users wrote:
On 5/24/25 5:10 AM, ToddAndMargo via users wrote:
On 5/24/25 4:56 AM, Patrick O'Callaghan wrote:
On Sat, 2025-05-24 at 04:47 -0700, ToddAndMargo via users wrote:
Hi All,
I still get all the trash with this:
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To 2>&1 > /dev/nul
I think I am putting the `2>&1 > /dev/nul` in the wrong place.
What am I doing wrong?
It's the wrong way round. The 2>&1 means "redirect the current fd 2 to the same place as fd 1", but at this point fd 1 is still unchanged. You also misspelled /dev/null but I assume that's a typo.
You want "... > /dev/null 2>&1".
poc
echo $msg | /usr/bin/mailx $smtp -s $IAm" Disk Status" -r $From $To
/ dev/null 2>&1
Mailx hangs. I think mailx thinks it is a parameter.
I lost contact with the server. Something is amiss.
I set it up on my computer.
I still get the trash
This worked: ... > /dev/null 2>&1
And it is exactly what Patrick told me to do. I kept reversing things in my mind.
ToddAndMargo via users wrote:
This worked: ... > /dev/null 2>&1
And it is exactly what Patrick told me to do. I kept reversing things in my mind.
It is well worth reading the Bash documentation on redirection:
https://www.gnu.org/software/bash/manual/bash.html#Redirections
Near the end of the main section, it says:
Note that the order of redirections is significant. For example, the command
ls > dirlist 2>&1
directs both standard output (file descriptor 1) and standard error (file descriptor 2) to the file dirlist, while the command
ls 2>&1 > dirlist
directs only the standard output to file dirlist, because the standard error was made a copy of the standard output before the standard output was redirected to dirlist.
A few lines later, the Redirecting Standard Output and Standard Error subsection is quite useful.
If you're writing scripts which run under bash (and likely some other shells, but you'd have to confirm compatibility), you can simplify life by using:
&>/dev/null
to send both stdout and stderr to /dev/null.
This is all in the bash man page as well, in the "REDIRECTION" section.