多机器执行ssh脚本

#!/bin/bash

Usage()
{
    echo "Usage: $0 'machine1 [machine2...]' 'command'"
}

OUTPUT_LOG="/tmp/output-$$.log"
ERROR_LOG="/tmp/error-$$.log"

MACHINES="$1";
COMMAND="$2";

echo "machines: $MACHINES"
echo "command: $COMMAND"

for strMachine in `echo $MACHINES`
do
    echo "run command for $strMachine";
    #echo "ssh '$strMachine' '$COMMAND' >> $OUTPUT_LOG.'$strMachine' 2>> $ERROR_LOG.'$strMachine' &"
    ssh "$strMachine" "$COMMAND" >> $OUTPUT_LOG."$strMachine" 2>> $ERROR_LOG."$strMachine" &
done

wait;
cat $OUTPUT_LOG.*
cat $ERROR_LOG.*

\rm -f $OUTPUT_LOG.*
\rm -f $ERROR_LOG.*
 

你可能感兴趣的:(ssh)