[112] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | #----------------------------------------------------------- |
---|
| 4 | # $Id: distexe.sh 112 2009-03-18 22:36:26Z rosiere $ |
---|
| 5 | #----------------------------------------------------------- |
---|
| 6 | |
---|
| 7 | # Need : test, echo, cd, dirname, basename, ssh |
---|
| 8 | |
---|
| 9 | #-----[ distexe_usage ]------------------------------------- |
---|
| 10 | function distexe_usage () |
---|
| 11 | { |
---|
| 12 | echo "Usage : ${0} file [ dir ]"; |
---|
| 13 | echo "Arguments : "; |
---|
| 14 | echo " * file : list of command"; |
---|
| 15 | echo " * dir : work directory (default is current directory)."; |
---|
| 16 | # echo " * nb_process : number of process (default (and maximum) is the number of processor)"; |
---|
| 17 | echo ""; |
---|
| 18 | echo "Note : "; |
---|
| 19 | echo " * File content list of command. Each line is execute by an host."; |
---|
| 20 | echo " A line can content many shell command."; |
---|
| 21 | echo " Don't forgot the final end of line (else the last command is not executed)"; |
---|
| 22 | echo " example : "; |
---|
| 23 | echo ' echo "export PATH=${PATH}:${HOME}/my_appli/bin; my_appli 13" > command_file.txt'; |
---|
| 24 | echo ' echo "export PATH=${PATH}:${HOME}/my_appli/bin; my_appli 21" >> command_file.txt'; |
---|
| 25 | echo ' echo "export PATH=${PATH}:${HOME}/my_appli/bin; my_appli 7" >> command_file.txt'; |
---|
| 26 | echo ' echo "" >> command_file.txt'; |
---|
| 27 | echo " * For each command, a directory (in work directory) is created : Task_X (X is the number of line in command file)."; |
---|
| 28 | echo " The command is execute in this directory. (Warning, set your environment !)."; |
---|
| 29 | echo " Two file is generate : \"distexe.output\" is the output (standard and error) of the execution, and \"distexe.command\" is the command lunch."; |
---|
| 30 | # echo " * A command empty (no command on a line of file) is a synchronisation with all process" |
---|
| 31 | echo " * The environment variable DISTEXE_HOSTS list hosts to execute command"; |
---|
| 32 | echo " After each host, a number is to the number of process. It's optionnal, the default value is the number of processor."; |
---|
| 33 | echo " example :"; |
---|
| 34 | echo ' export DISTEXE_HOSTS="localhost/1 nod/4 gdi/2"'; |
---|
| 35 | echo " * All hosts must have network file systems (per example nfs or samba)"; |
---|
| 36 | echo " Work directory must be in this network file systems !"; |
---|
| 37 | echo ""; |
---|
| 38 | exit; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | #-----[ distexe_test_usage ]-------------------------------- |
---|
| 42 | function distexe_test_usage () |
---|
| 43 | { |
---|
| 44 | if test ${#} -ne 1 -a ${#} -ne 2; then |
---|
| 45 | distexe_usage; |
---|
| 46 | fi; |
---|
| 47 | |
---|
| 48 | if test -z "${MORPHEO_SCRIPT}"; then |
---|
| 49 | echo "Environment variable MORPHEO_SCRIPT is not set"; |
---|
| 50 | distexe_usage; |
---|
| 51 | fi; |
---|
| 52 | |
---|
| 53 | if test ! -f ${1}; then |
---|
| 54 | echo "File \"${1}\" is invalid"; |
---|
| 55 | distexe_usage; |
---|
| 56 | fi; |
---|
| 57 | |
---|
| 58 | if test ! -s ${1}; then |
---|
| 59 | echo "File \"${1}\" is empty."; |
---|
| 60 | distexe_usage; |
---|
| 61 | fi; |
---|
| 62 | |
---|
| 63 | if test ${#} -eq 2; then |
---|
| 64 | if test ! -d ${2}; then |
---|
| 65 | echo "Directory \"${2}\" is invalid."; |
---|
| 66 | distexe_usage; |
---|
| 67 | fi; |
---|
| 68 | fi; |
---|
| 69 | |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | #-----[ distexe ]------------------------------------------- |
---|
| 73 | function distexe () |
---|
| 74 | { |
---|
| 75 | distexe_test_usage ${*}; |
---|
| 76 | |
---|
| 77 | # construct file command with absolute path |
---|
| 78 | cd $(dirname ${1}); |
---|
| 79 | local FILE_CMD=${PWD}/$(basename ${1}); |
---|
| 80 | cd -; |
---|
| 81 | |
---|
| 82 | # Absoulte path of work directory |
---|
| 83 | local DIR_EXE; |
---|
| 84 | if test ${#} -eq 2; then |
---|
| 85 | cd ${2}; |
---|
| 86 | DIR_EXE=${PWD}; |
---|
| 87 | cd -; |
---|
| 88 | else |
---|
| 89 | DIR_EXE=${PWD}; |
---|
| 90 | fi; |
---|
| 91 | |
---|
| 92 | local hosts="${DISTEXE_HOSTS}"; |
---|
| 93 | |
---|
| 94 | for line in ${hosts}; do |
---|
| 95 | local host=$(echo ${line} | cut -d/ -f1); |
---|
| 96 | local -i nb_process=$(echo ${line} | cut -d/ -f2); |
---|
| 97 | |
---|
| 98 | echo " * station : ${host} (${nb_process}) ... "; |
---|
| 99 | |
---|
| 100 | # lunch service |
---|
| 101 | local cmd="export MORPHEO_SCRIPT=${MORPHEO_SCRIPT};${MORPHEO_SCRIPT}/execute_n.sh ${DIR_EXE} ${FILE_CMD} ${nb_process};"; |
---|
| 102 | ssh ${host} ${cmd} & |
---|
| 103 | done; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | #-----[ Corps ]--------------------------------------------- |
---|
| 107 | distexe ${*}; |
---|