#!/bin/bash # Verify an NNTP server is running and can list/post/read # Usage: scripts/verify-nntp.sh [host] [port] HOST="${1:-localhost}" PORT="${2:-119}" echo "=== NNTP Server Verification ===" echo "Target: $HOST:$PORT" echo # 1. Check port is open echo "--- Step 1: Port open? ---" ss -tlnp 2>/dev/null | grep -qE ":${PORT}\s" && echo "PASS: Port $PORT is listening" || { echo "FAIL: Port $PORT not listening"; exit 1; } # 2. Connect and get greeting echo "--- Step 2: Server greeting ---" GREETING=$(echo -e "QUIT\r\n" | timeout 5 nc -w 3 "$HOST" "$PORT" 2>&1) echo "$GREETING" | head -1 if echo "$GREETING" | head -1 | grep -q "200 "; then echo "PASS: Got valid NNTP greeting" else echo "FAIL: No NNTP greeting received" exit 1 fi # 3. List newsgroups echo "--- Step 3: LIST newsgroups ---" GROUPS=$(echo -e "MODE READER\r\nLIST\r\nQUIT\r\n" | timeout 5 nc -w 3 "$HOST" "$PORT" 2>&1) if echo "$GROUPS" | grep -q "215 "; then echo "PASS: LIST command works" echo "Groups:" echo "$GROUPS" | grep -v "^200\|^215\|^\.\|^205" else echo "FAIL: LIST command failed" exit 1 fi # 4. Post a test article echo "--- Step 4: POST test article ---" POST_RESULT=$(echo -e 'POST\r\nFrom: verify@test.local\r\nNewsgroups: local.test\r\nSubject: NNTP Docker verification\r\n\r\nVerification article from automated test.\r\n.\r\nQUIT\r\n' | timeout 5 nc -w 3 "$HOST" "$PORT" 2>&1) if echo "$POST_RESULT" | grep -q "240 "; then echo "PASS: Article posted successfully" else echo "FAIL: Posting failed" echo "$POST_RESULT" exit 1 fi # 5. Read it back echo "--- Step 5: Read test article ---" READ_RESULT=$(echo -e "GROUP local.test\r\nARTICLE 1\r\nQUIT\r\n" | timeout 5 nc -w 3 "$HOST" "$PORT" 2>&1) if echo "$READ_RESULT" | grep -q "220 "; then SUBJECT=$(echo "$READ_RESULT" | grep "^Subject: ") echo "PASS: Article readable — $SUBJECT" else echo "FAIL: Reading article failed" exit 1 fi echo echo "=== All checks PASSED ==="