2025-02-25 18:51:25 +08:00

48 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
FILE_NAME="h5.zip"
# 当前服务器上的文件路径
LOCAL_FILE="/tmp/$FILE_NAME"
# 目标服务器信息格式IP地址:端口)
SERVERS=(
"172.26.1.9:22"
"172.26.1.15:22"
)
# 目标路径
TARGET_DIR="/home/ubuntu"
# 目标文件路径
TARGET_FILE="$TARGET_DIR/$FILE_NAME"
# 目标解压路径
TARGET_EXTRACT_DIR="/usr/local/nginx/html/h5"
# 1. 删除所有服务器上原始包,并拷贝新文件
for SERVER in "${SERVERS[@]}"; do
# 获取 IP 和端口
IP=$(echo $SERVER | cut -d ':' -f 1)
PORT=$(echo $SERVER | cut -d ':' -f 2)
# 删除原始包
echo "Deleting $FILE_NAME on $IP"
ssh -p $PORT ubuntu@$IP "rm -rf $TARGET_DIR/$FILE_NAME"
# 拷贝新文件
echo "Copying $LOCAL_FILE to $IP:$TARGET_DIR"
scp -P $PORT $LOCAL_FILE ubuntu@$IP:$TARGET_DIR
# 删除原解压路径
echo "Deleting $TARGET_EXTRACT_DIR on $IP"
ssh -p $PORT ubuntu@$IP "sudo rm -rf $TARGET_EXTRACT_DIR"
# 解压文件
echo "Unzipping $FILE_NAME on $IP"
ssh -p $PORT ubuntu@$IP "sudo unzip $TARGET_FILE -d $TARGET_EXTRACT_DIR"
done
echo "All tasks completed."