初始提交
This commit is contained in:
44
py-deploy/bin/mexec
Normal file
44
py-deploy/bin/mexec
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
|
||||
BASEDIR=$(cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
|
||||
SSH_KEY=${BASEDIR}/$(ls ${BASEDIR} | egrep '.pem$' | head -n 1)
|
||||
|
||||
if [ $# -lt 1 ]; then
|
||||
>&2 echo "Execute command on each host."
|
||||
>&2 echo "Usage: $0 <cmd> | $0 -f <file>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NOMASTER=0
|
||||
if [ "$1" == "--no-master" ]; then
|
||||
NOMASTER=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ "$1" == "-f" ]; then
|
||||
file=$2
|
||||
else
|
||||
cmd="$@"
|
||||
fi
|
||||
|
||||
user=$(whoami)
|
||||
N=0
|
||||
for host in $(cat ${BASEDIR}/hosts | grep -v "^#" | awk '{print $1}')
|
||||
do
|
||||
if [ "${NOMASTER}" == "1" ] && cat ${BASEDIR}/hosts | grep "master" | grep ${host} >/dev/null
|
||||
then
|
||||
continue
|
||||
fi
|
||||
|
||||
N=$(expr ${N} + 1)
|
||||
if [ "x${cmd}" != "x" ]; then
|
||||
exe_cmd=$(echo "${cmd}" | sed "s/\${N}/${N}/")
|
||||
echo "${user}@${host}> ${exe_cmd}"
|
||||
echo "${exe_cmd}" | ssh -T ${host}
|
||||
else
|
||||
echo "${user}@${host}> ${file}"
|
||||
${file}> ssh -T ${host}
|
||||
fi
|
||||
echo "(exit $?)"
|
||||
echo ""
|
||||
done
|
||||
Reference in New Issue
Block a user