Hello -
I have a script which looks for filesystem usage and its a common script for all servers I have . On few servers, we do not have a FS available and getting the output as
No such file or directory
, which is expected. I am not in favor of having an if condition to have list of servers added and verify for that specific FS only on those servers.
wondering if there is a way I can ignore this error to show-up on output itself when someone run that script?
Noe - I write the output of the script to a temp txt file and use it for different purpose.
Today I am using on that specific line , instead of whole script executing. But
this line making me to think , if for some reason that FS is not mounted during patching then I am missing that important message . Any way I can avoid ? I guess answer would be NO.
You could redirect error messages to a (log-)file, for a later review, or to parse for known issues after the 'main' commands.
So instead of >/dev/null you would be using >>/path/to/logfile .
The following "descriptor magic" should work with all shells
{
# Descriptor 2 goes where descriptor 1 currently goes to (the pipe!), then descriptor 1 goes to where descriptor 3 currently goes to (set at the end of the braces)
# In short: 2 becomes a dup of 1 then 1 becomes a dup of 3
ls -ld / /notthere 2>&1 1>&3 | grep -v "No such file or directory"
# Restore to the original descriptors:
# 3 becomes a dup of 1 then 1 becomes a dup of 2
} 3>&1 1>&2
The redirections of the ( code block } happens before the code block is run.