Last active
March 5, 2025 23:26
-
-
Save willjasen/77e78b5e33934eb33862c9e142763fc1 to your computer and use it in GitHub Desktop.
test NTP accuracy of local Starlink dish vs. ntp.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
######## | |
# test NTP accuracy of local Starlink dish vs. ntp.org | |
######## | |
# List of NTP servers; Starlink is first, followed by ntp.org | |
SERVERS=("192.168.100.1" "us.pool.ntp.org") | |
COUNT=10 # Number of times to run sntp per server | |
SUMMARY_FILE=$(mktemp) # Store summary results | |
for SERVER in "${SERVERS[@]}"; do | |
TEMP_FILE=$(mktemp) | |
echo -e "\nRunning sntp $COUNT times against $SERVER..." | |
for i in $(seq 1 $COUNT); do | |
OUTPUT=$(sntp -sS "$SERVER" 2>/dev/null) | |
echo "$OUTPUT" >> "$TEMP_FILE" | |
echo "[$i/$COUNT] $OUTPUT" | |
sleep 0.5 # Adjust sleep time if needed | |
done | |
echo -e "\nSummary for $SERVER:" | |
awk -v server="$SERVER" '{ | |
adj=$1 * 1000; # Convert to milliseconds | |
sum+=adj; sum_sq+=adj*adj; count+=1; | |
} | |
END { | |
mean=sum/count; | |
stddev=sqrt(sum_sq/count - mean*mean); | |
printf "%s: Mean adjustment: %.4f ms | Standard deviation: %.4f ms\n", server, mean, stddev; | |
}' "$TEMP_FILE" >> "$SUMMARY_FILE" | |
rm "$TEMP_FILE" | |
done | |
echo -e "\n=========================" | |
echo "Final Summary (Comparison)" | |
echo "=========================" | |
cat "$SUMMARY_FILE" | |
# Find most stable and most accurate server (compatibility fix) | |
BEST_SERVER=$(awk 'NR==1 || $9 < min {min=$9; best=$1} END {print best}' "$SUMMARY_FILE") | |
MOST_ACCURATE_SERVER=$(awk 'NR==1 || ($4 < 0 ? -$4 : $4) < min {min=($4 < 0 ? -$4 : $4); accurate=$1} END {print accurate}' "$SUMMARY_FILE") | |
echo -e "\nMost Stable Server (Lowest Std Dev): $BEST_SERVER" | |
echo "Most Accurate Server (Closest to 0 Mean Adjustment): $MOST_ACCURATE_SERVER" | |
rm "$SUMMARY_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment