all-wp-site-shell.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # 定义目标目录(通过参数传入)
  3. target_dir="$1"
  4. if [ ! -d "$target_dir" ]; then
  5. echo "错误: 目标目录不存在 [$target_dir]"
  6. exit 1
  7. fi
  8. echo "======================================"
  9. echo "目标目录 : $target_dir"
  10. echo "开始时间 : $(date)"
  11. echo "======================================"
  12. # 遍历所有子目录(排除隐藏目录)
  13. find "$target_dir" -maxdepth 1 -type d ! -path "$target_dir" ! -path '*/.*' | while read -r subdir; do
  14. echo "▶ 进入目录: $subdir"
  15. # 进入子目录
  16. cd $subdir;
  17. sed -i 's/v3-site.adwebcloud.com/v3.sohoeb2b.com/g' wp-config.php
  18. ######处理缓存,替换数据库旧地址
  19. cp /opt/adweb3/config/wp-cli.phar $subdir
  20. target_dir=$(basename "$subdir")
  21. echo "当前站点code为:$target_dir"
  22. php ./wp-cli.phar search-replace "$target_dir.v3-site.adwebcloud.com" "$target_dir.v3.sohoeb2b.com" --allow-root
  23. php ./wp-cli.phar search-replace "https://$target_dir.v3-site.adwebcloud.com" "https://$target_dir.v3.sohoeb2b.com" --allow-root
  24. php ./wp-cli.phar cache flush --allow-root
  25. rm -rf wp-cli.phar
  26. status="✓ 成功"
  27. # # 执行脚本并记录结果
  28. if [ $? -eq 0 ]; then
  29. status="✓ 成功"
  30. else
  31. status="x 失败"
  32. fi
  33. echo "状态: $status"
  34. echo "--------------------------------------"
  35. done
  36. echo "======================================"
  37. echo "完成时间 : $(date)"
  38. echo "所有子目录处理完成!"
  39. echo "======================================"