Suppressing errors from command output

Hi,

When I run the command "print_manifest | grep "Main Memory", I get the note :

# /opt/ignite/bin/print_manifest | grep "Main Memory"
NOTE: Could not read the /etc/resolv.conf file.
    Main Memory:        196498 MB
#

How do I suppress the part :

NOTE: Could not read the /etc/resolv.conf file.

The file /etc/resolv.conf does not exist in the server, because we do not use DNS for our hostname resolution. However, this NOTE does not pop once I create the resolv.conf file. But is this a good solution?

Please advise.

Did you consider redirecting stderr to /dev/null ?

Hi,

The script expects to see the resolve.conf file, so is correctly identifying the missing file - touching the file removes the error.

There are a number of options, the simplest is probably to do;

touch /etc/resolv.conf
chmod 440 /etc/resolv.conf

Alternatively you could send the stderr to /dev/null

Your final option would be to modify the script and put the offendin part of the script inside a test condition - running if the resolv.conf file exists.

Regards

Gull04

1 Like

I tried these methods to redirect stderr to /dev/null, and still that message pops :

$ sudo print_manifest | grep "Main Memory" > /dev/null 2>&1
NOTE: Could not read the /etc/resolv.conf file.
$ sudo print_manifest | grep "Main Memory" &>/dev/null
[1]     7684
$ NOTE: Could not read the /etc/resolv.conf file.
    Main Memory:        196498 MB

Are the commands I am using above correct?
If so, then seems like redirecting the error wont work. Need to touch the file?

You are piping the command's stdout to grep and then redirecting grep 's stderr to the null device. Where does the command's stderr go to?

EDIT: Alternatively, make it all a "compound command":