Verifying Students have Posted to the Newsgroup

A utility that will download posts from a newsgroup,, is attached to this document (the Wiki insists on appending .txt; just rename it). It will be wrapped by a program similar to the following, which should then be run frequently (every minute) from a cron job:


export PATH=`/bin/showpath gnu standard`
cd /u/cs135/newsgroup
./ uw.cs.cs135 >/dev/null
grep '^From: ' `grep -l '^References: $' *`\
        | perl -lne 'print $1 if /\<(.*?)@.*uwaterloo\.ca\>/' > $tmpfile
mv $tmpfile $realfile

The portion after the string "^References:" in the grep line must be replaced by the message-ID of the initial newsgroup post, and the course name should be replaced on each line it occurs with the proper course.

Changes that can/should be made and tested include:

  • Making the use of a command like whoami to avoid hard-coding in a particular course name in several places so this script can be copied with fewer modifications.
  • Requiring this script is in the same directory as (which it was anyway), so that the cd line should be able to be changed to the less fragile cd $(dirname $0).

The test.exe program can then take an action similar to the following:

#!/usr/bin/env bash
readonly POSTS="/u/$course/newsgroup/a0_done"
if [ `grep '^'$student'$' $POSTS |  wc -w` -gt 0 ]; then 
        echo '100' >&3
        echo "The appropriate email address was used for a newsgroup post." >&4
        echo '0' >&3
        echo "An e-mail from $student's uwaterloo address was not found on the newsgroup." >&4

Please note the importance of wrapping the student userid in ^ and $. This is done to ensure that the userid is actually listed in full, and is not just a substring of another userid, which could lead to false positives.

TODO: While it is unlikely for a userid to contain a space, or for the POSTS filename to contain whitespace, should the grep in text.exe instead be `grep "^$student$" "$POSTS" | ...`?
Topic attachments
I Attachment Action Size Date Who Comment
Texttxt manage 5.7 K 2009-07-23 - 14:15 TerryVaskor Utility that will download newsgroup articles
Topic revision: r5 - 2010-09-20 - TerryVaskor
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback