how do I parse output from ntpq?
<p>I am fairly new to bash scripting... I have an issue with a cronjob where I get too many emails when "ntpq: read: Connection refused" error comes up. I want to create a conditional when this error shows up, DO NOT send the email. </p>

<p>However, I can't seem to parse the output from "nptq -nc peers". I did try to redirect the output of the cronjob to a <code>test.txt</code> file and then create another cronjob that parses that file. However, I feel like there is a better solution.</p>

<p>Thanks for your help!</p>

<p>Here is my code for the cronjob</p>

<pre><code>#!/bin/bash
limit=10101010101010101010000   # Set your limit in milliseconds here
offsets=$(/usr/sbin/ntpq -nc peers | /usr/bin/tail -n +3 | awk 'BEGIN { FS = " " } ; { print $9 }' | /usr/bin/tr -d '-')
for offset in ${offsets}; do
    if echo $offset $limit | awk '{exit $1&gt;$2?0:1}'
            then
            echo "NTPD offset $offset &gt; $limit. Please investigate"
            exit 1
    fi
done
</code></pre>