初始提交

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

21
py-deploy/bin/mscp Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
BASEDIR=$(cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
SSH_KEY=${BASEDIR}/$(ls ${BASEDIR} | egrep '.pem$' | head -n 1)
if [ $# -ne 2 ]; then
echo "Copy file to all hosts"
echo "Usage: $0 <source> <target>"
exit 1
fi
for host in $(cat ${BASEDIR}/hosts | grep -v "^#" | awk '{print $1}')
do
if ifconfig | grep inet | grep "${host}" >/dev/null ; then
# skip current host
continue
fi
#scp -i ${SSH_KEY} -r $1 ${host}:$2
scp -r $1 ${host}:$2
done

19
py-deploy/bin/ssh Normal file
View File

@@ -0,0 +1,19 @@
#!/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 "Usage: $0 <hostname>"
exit 1
fi
host=$1
user=$(whoami)
for h in $(cat ${BASEDIR}/hosts | grep -v "^#" | egrep "\\s+${host}(\\s+.*)*$" | awk '{print $1}')
do
host=${h}
break
done
ssh -i ${SSH_KEY} ${host}