[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r19998: {torflow} Clean up cron.sh so it errors cleanly if no results exist. A (torflow/trunk/NetworkScanners/BwAuthority)



Author: mikeperry
Date: 2009-07-14 00:14:38 -0400 (Tue, 14 Jul 2009)
New Revision: 19998

Modified:
   torflow/trunk/NetworkScanners/BwAuthority/README.BwAuthorities
   torflow/trunk/NetworkScanners/BwAuthority/aggregate.py
   torflow/trunk/NetworkScanners/BwAuthority/cron.sh
Log:

Clean up cron.sh so it errors cleanly if no results exist.
Also document cron.sh a bit better in the README.



Modified: torflow/trunk/NetworkScanners/BwAuthority/README.BwAuthorities
===================================================================
--- torflow/trunk/NetworkScanners/BwAuthority/README.BwAuthorities	2009-07-14 03:53:44 UTC (rev 19997)
+++ torflow/trunk/NetworkScanners/BwAuthority/README.BwAuthorities	2009-07-14 04:14:38 UTC (rev 19998)
@@ -108,14 +108,21 @@
 
 8. Set up a cron job to submit results
 
-Ideally a cron job would aggregate the results and provide them to your
-directory authority at least every four hours, but more often is better:
+The provided cron.sh script is meant to be used in a cron job to aggregate the
+results and provide them to your directory authority at least every four
+hours, but more often is better:
 
 # echo "45 0-23 * * * $HOME/code/torflow-trunk/NetworkScanners/BwAuthority/cron.sh" | crontab
 
 Note that authorities vote every hour starting at 50 past the hour.
 Hence the 45 to give us time to gather the results and copy them over.
 
+The script has two locations that you should consider editing. First
+is the SCANNER_DIR variable, which you should point at this 
+directory. The second is the bit at the end, where you need to choose
+if you want to scp the result (held in file $OUTPUT) to a different
+machine, or just copy it into place.
+
 In general, if you have any other bandwidth-intensive backup or mirror
 cron jobs on your scanning server, you should schedule them for between
 1:30am and 4:30am, as this is when your scanner will be idle. If this is

Modified: torflow/trunk/NetworkScanners/BwAuthority/aggregate.py
===================================================================
--- torflow/trunk/NetworkScanners/BwAuthority/aggregate.py	2009-07-14 03:53:44 UTC (rev 19997)
+++ torflow/trunk/NetworkScanners/BwAuthority/aggregate.py	2009-07-14 04:14:38 UTC (rev 19998)
@@ -193,7 +193,11 @@
       except ValueError,e:
         print "Conversion error "+str(e)+" at "+l
     fp.close()
-   
+
+  if len(nodes) == 0:
+    plog("NOTICE", "No scan results yet.")
+    sys.exit(1)
+ 
   pre_strm_avg = sum(map(lambda n: n.avg_strm_bw(), nodes.itervalues()))/ \
                   float(len(nodes))
   pre_filt_avg = sum(map(lambda n: n.avg_filt_bw(), nodes.itervalues()))/ \
@@ -264,3 +268,4 @@
  
 if __name__ == "__main__":
   main(sys.argv)
+  sys.exit(0)

Modified: torflow/trunk/NetworkScanners/BwAuthority/cron.sh
===================================================================
--- torflow/trunk/NetworkScanners/BwAuthority/cron.sh	2009-07-14 03:53:44 UTC (rev 19997)
+++ torflow/trunk/NetworkScanners/BwAuthority/cron.sh	2009-07-14 04:14:38 UTC (rev 19998)
@@ -1,11 +1,16 @@
 #!/bin/sh
+
+SCANNER_DIR=~/code/torflow-trunk/NetworkScanners/BwAuthority
+
 TIMESTAMP=`date +%Y%m%d-%H%M`
-SCANNER_DIR=~/code/torflow-trunk/NetworkScanners/BwAuthority
 TOR_DEST=$SCANNER_DIR/bwscan.V3BandwidthsFile
 OUTPUT=$SCANNER_DIR/data/bwscan.${TIMESTAMP}
 
 cd $SCANNER_DIR # Needed for import to work properly.
 $SCANNER_DIR/aggregate.py $SCANNER_DIR/data $OUTPUT
 
-cp $OUTPUT $TOR_DEST
-#scp $OUTPUT tor@xxxxxxxxxxxxx:/var/lib/tor.bwscans/bwscan
+if [ $? == 0 ]
+then
+ cp $OUTPUT $TOR_DEST
+ scp $OUTPUT bwscan@xxxxxxxxxxxxxxxx:/var/lib/tor.bwscans/bwscan
+fi