#!/bin/bash # 定义目标目录(通过参数传入) target_dir="$1" if [ ! -d "$target_dir" ]; then echo "错误: 目标目录不存在 [$target_dir]" exit 1 fi echo "======================================" echo "目标目录 : $target_dir" echo "开始时间 : $(date)" echo "======================================" # 遍历所有子目录(排除隐藏目录) find "$target_dir" -maxdepth 1 -type d ! -path "$target_dir" ! -path '*/.*' | while read -r subdir; do echo "▶ 进入目录: $subdir" # 进入子目录 cd $subdir; sed -i 's/v3-site.adwebcloud.com/v3.sohoeb2b.com/g' wp-config.php ######处理缓存,替换数据库旧地址 cp /opt/adweb3/config/wp-cli.phar $subdir target_dir=$(basename "$subdir") echo "当前站点code为:$target_dir" php ./wp-cli.phar search-replace "$target_dir.v3-site.adwebcloud.com" "$target_dir.v3.sohoeb2b.com" --allow-root php ./wp-cli.phar search-replace "https://$target_dir.v3-site.adwebcloud.com" "https://$target_dir.v3.sohoeb2b.com" --allow-root php ./wp-cli.phar cache flush --allow-root rm -rf wp-cli.phar status="✓ 成功" # # 执行脚本并记录结果 if [ $? -eq 0 ]; then status="✓ 成功" else status="x 失败" fi echo "状态: $status" echo "--------------------------------------" done echo "======================================" echo "完成时间 : $(date)" echo "所有子目录处理完成!" echo "======================================"