In this case, the “problem” is that it ntpdcsends a message with a timeout to a standard error, and not a standard error, so it grepdoes not see it at the entrance to the pipe. You can eliminate the standard routing error of the command ntpdcto standard output:
if ntpdc -n -c monlist $SERVER 2>&1 | grep "timed out"
then
echo "Server won't let You use monlist."
exit 0
else
echo "Server will let You use monlist."
fi
source
share