#!/bin/sh # # # File: radicron # Author: Dael Maselli - LNF - INFN # Date: 31 August 2007 # Purpose: Randomly distributes crontab accross nodes (ex. cluster) # # Requires: GNU sed, md5sum, host, find, printf, cat in PATH. # # Usage: Edit SPOOLDIR variable and insert an "as sync as possible" # directory shared accross radicron nodes. # Insert `radicron ` into your crontab. # # Changed: 04 July 2008 # creates directory structure # cd /tmp/ SPOOLDIR=/HIDDEN_FOR_INFN_SECURITY DELAY=5 ############################################################################# COMMAND=$* cridnd=`echo $COMMAND | md5sum | sed 's@ -@@'` crid=$cridnd/`date +%G%m%d/%H/%M` mkdir -p $SPOOLDIR/$crid [ -f $SPOOLDIR/$crid/won ] && exit; bet=`md5sum /proc/net/dev | sed -r 's@[^0-9]@@g' | sed -r 's@^(.....).*$@\1@'``printf %012d \`host $HOSTNAME | sed -r 's@^.+has address |\\.@@g'\`` echo $bet > $SPOOLDIR/$crid/bet.$HOSTNAME sleep $DELAY [ -f $SPOOLDIR/$crid/won ] && exit; for vsbet in `find $SPOOLDIR/$crid -name "bet.*"`; do [ `cat $vsbet` -gt $bet ] && exit; done echo "NODE:$HOSTNAME" > $SPOOLDIR/$crid/won echo "CMDL:$COMMAND" >> $SPOOLDIR/$crid/won $COMMAND exs=$? /usr/sbin/tmpwatch --mtime 240 $SPOOLDIR/$cridnd rmdir --ignore-fail-on-non-empty $SPOOLDIR/$cridnd echo "EXIT:$exs" >> $SPOOLDIR/$crid/won exit $exs