#!/bin/csh # INTRODUCTION # ============ # A primitive distributed processing/load balancing script. # A script that uses a internal list of machines and a supplied list of # redirected commands to run one job on each machine until all done. # NOTE: The commands must not produce any output that has not been # redirected elsewhere (eg. file or /dev/null) or script may hang. # BOTH stdout and stderr must be redirected eg >& /dev/null # 950726 Jeremy Added option to supply machines list as a file # IMPROVEMENTS NEEDED # =================== # Should put a check to test if machines actually still exist # Should check to see if machines are being used already :-) One day ! # =================================================================== # Default Machine lists set tens = (crick watson franklin); set fives = (trna pcr geneman wat10 taq alu enhancer worm fra01 fra02 fra03); #set quietfives = (trna pcr geneman wat10); set machines = ($tens $fives); # =================================================================== # Check command line parameters if ((${#argv} != 1) && (${#argv} != 3)) then echo "USAGE: spreader file_of_redirected_commands [-servers server_file]"; exit 1; endif set comm_file=$argv[1]; if (! -e $comm_file) then echo "$comm_file does not exist."; exit 1; endif if (${#argv} == 3) then set flag = $argv[2]; if ($flag != "-servers") then echo "USAGE: spreader file_of_redirected_commands [-servers server_file]"; exit 1; else set server_file = $argv[3]; if (! -e $server_file) then echo "Cannot open the file of server names $server_file"; exit 1; endif set machines = (`cat $server_file | tr '\012' ' '`); endif endif # =================================================================== # Create the table of available machines if (-e idle_machines.$$) then echo "idle_machines.$$ already exists. Try again from another window"; exit 2; endif mkdir idle_machines.$$; foreach machine ($machines) touch idle_machines.$$/$machine; if (! -e idle_machines.$$/$machine) then echo "Couldn't create lockfile idle_machines/$machine"; exit 2; endif echo "Marked $machine as available"; end # =================================================================== # Get each command in turn and execute it on available machines set uniq = $$; set comm_line_num = 1; # keep track of commands sent already set command = `sed -n ${comm_line_num}p $comm_file`; set comm_c_count = `echo $command | tr -cd '[A-Z][a-z]' | wc -c | awk '{print $1}'` while ($comm_c_count > 1) set free_m_count = `\ls idle_machines.${uniq} | wc -l | awk '{print $1}'` if ($free_m_count >= 1) then set free_m = `\ls idle_machines.${uniq} | head -1`; # Name of idle machine \rm -f idle_machines.${uniq}/$free_m ; # Remove name of used machine rsh -n $free_m "($command)"; touch idle_machines.${uniq}/$free_m & echo "Executing on $free_m" `date`; @ comm_line_num ++; set command = `sed -n ${comm_line_num}p $comm_file`; set comm_c_count = `echo $command | tr -cd '[A-Z][a-z]' | wc -c | awk '{print $1}'` else sleep 10; endif end #\rm -f idle_machines.${uniq} set date = `date`; echo "SUCCESS at $date"; exit 0;