2

I'm trying to avoid printing messages to the console received when a lun is not found during an ssh command. SSH is to a NetApp filer. Command is being run on a Solaris 10 host.

Here is some of the code I am executing:

for filer in <list>
do
echo $filer
ssh $filer lun show <lunpath> |grep vol
...
done

If the LUN is found the code works fine, but if the LUN is not found the SSH command returns "lun show: No such LUN exists"

I've tried multiple grep and egrep commands, including -v variants... but I still get the "lun show: No such LUN exists" message printed to the console.

What do I have to do to skip printing this line to the console?

1 Answer 1

2

Newer ssh seem to bring back stdout and stderr from the remote host as two distinct streams.

To create a filter that combines both stdout and stderr you could do:

ssh $filer lun show <lunpath> 2>&1 |grep vol

To send stderr to a separate file, you could do:

ssh $filer lun show <lunpath> 2>lun.show.stderr |grep vol
if [ -s lun.show.stderr ]; then
   # there was some stderr output
   grep -v "No such LUN exists" lun.show.stderr
fi

To discard stderr:

ssh $filer lun show <lunpath> 2>/dev/null | grep vol

Note that this might hide real errors and make debugging difficult.

1
  • 1
    or ssh $filer lun show <lunpath> '2>/dev/null' | grep vol to not suppress ssh errors only lun show errors
    – Jasen
    Jun 9, 2016 at 2:39

You must log in to answer this question.