12
This commit is contained in:
joy 2025-12-02 15:35:09 +08:00
parent 1c3d7b73b3
commit 65ce3024fe
1 changed files with 9 additions and 1 deletions

View File

@ -5,7 +5,7 @@ set -e
# ========== 日志配置 ==========
# 定义日志文件(带时间戳,避免覆盖)
LOG_FILE="/opt/deploy_$(date +%Y%m%d_%H%M%S).log"
LOG_FILE="/opt/deploy.log"
# 将stdout和stderr同时重定向到tee前台输出+日志写入)
exec > >(tee -a "$LOG_FILE") 2>&1
@ -20,6 +20,14 @@ red_echo() {
# ========== 执行步骤 ==========
# 1. 同步远程/opt目录到本地
green_echo "开始同步远程服务器172.51.4.158的/opt目录..."
# 安装sshpass
green_echo "开始安装sshpass..."
if apt install -y sshpass; then
green_echo "sshpass安装成功"
else
red_echo "sshpass安装失败请检查网络或软件源配置"
exit 1
fi
sshpass -p 'Zp5#tr6#xm9' rsync -avzP -e "ssh -o StrictHostKeyChecking=no" root@172.51.4.158:/opt/* /opt/
green_echo "目录同步完成!"