linux - Bash script - if and grep won't work -


This community really feels good, so I thought I would ask a question -

I is a small script but it will not be timed with output only:

  #! / Bin / bash echo -n "Enter the NTP server address:" If NTPDC-NC Monitor $ server | Grep "timed out", then "echo" server will not let you use the monlist. "Exit 0 else echo" server will allow you to use the monlist. "Fi  

Any thoughts? Thanks :)

ntpdc timeout message sends the standard error, not the standard, hence the grep You do not see the input of the pipes. You can measure the standard output by using standard code of ntpdc command:

  if ntpdc -n -c monlist $ server 2 & gt; and 1 | Grep "expired", then "echo" Sir God will not let you use Monlist. "Exit 0 else echo" server will let you use Monlist. " Fi  

Comments