diff-memberships: cleanup to make it more useable
authorAlex Dehnert <adehnert@mit.edu>
Fri, 27 Sep 2013 21:56:51 +0000 (17:56 -0400)
committerAlex Dehnert <adehnert@mit.edu>
Fri, 27 Sep 2013 21:56:51 +0000 (17:56 -0400)
Use an absolute path to the data directory, not a relative one; loop inside the
script, not outside; etc..

diff-memberships

index 92016f293c08f792e653e7b7fcdccf0ab646d063..0b1d10abe9ec104cf220201ae8a4b097a7beec44 100755 (executable)
@@ -2,27 +2,41 @@
 
 qy="athrun ops qy"
 
-#queries="get_ace_use get_lists_of_member"
+datadir=${1:-$HOME/Private/listdiff}
+if ! [[ -d "$datadir" ]]; then
+    echo "Please create and initialize the data directory"
+    echo "($datadir)"
+    echo "and rerun this script."
+    exit 1
+fi
+cd "$datadir"
+
 queries=( "gaus" "glom" )
 subjectname="$USER"
-for query in ${queries[@]}; do
-    for mod in "" "r"; do
-        hmod=$mod
-        if [ -z "$mod" ]; then hmod="nr"; fi
-        $qy $query ${mod}user "$subjectname" -s | sort > data/$query-user-$hmod.txt
-        $qy $query ${mod}kerberos "$subjectname@ATHENA.MIT.EDU" -s | sort > data/$query-kerb-$hmod.txt
+
+while true; do
+    printf "\n\n"
+    date
+
+    for query in ${queries[@]}; do
+        for mod in "" "r"; do
+            hmod=$mod
+            if [ -z "$mod" ]; then hmod="nr"; fi
+            $qy $query ${mod}user "$subjectname" -s | sort > $query-user-$hmod.txt
+            $qy $query ${mod}kerberos "$subjectname@ATHENA.MIT.EDU" -s | sort > $query-kerb-$hmod.txt
+        done
     done
-done
 
-cd "$(dirname "$0")/data/"
+    stat="$(git diff --stat)"
 
-stat="$(git diff --stat)"
+    for file in *.txt; do
+        result="$(git diff "$file")"
+        if [ -n "$result" ]; then
+            zwrite -c "$subjectname-lists" -i "$file" "$subjectname" -m "$result"
+        fi
+    done
 
-for file in *.txt; do
-    result="$(git diff "$file")"
-    if [ -n "$result" ]; then
-        zwrite -c "$subjectname-lists" -i "$file" "$subjectname" -m "$result"
-    fi
-done
+    git commit -a -m "$(printf "Regular list update: %s\n\n%s" "$(date)" "$stat")"
 
-git commit -a -m "$(printf "Regular list update: %s\n\n%s" "$(date)" "$stat")"
+    sleep 5m
+done