初始提交

This commit is contained in:
2026-03-23 10:33:13 +08:00
commit addf335bc6
15 changed files with 1252 additions and 0 deletions

44
py-deploy/bin/mexec Normal file
View 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