WordPressをcronで自動更新。1日おきに最新に!

Wordpress
wordpress

概要

  • Wordperssのプラグインか何かの脆弱性を突かれて、Wordpressがクラックされてしまった
    • バックドアのファイルをあちこちに置かれた。
    • アクセスログからの進入経路は特定できなかった。
  • もともと、Wordpress管理画面からプラグインを簡単に更新できるように、Wordpressのディレクトリ自体をwritableにして運用していた。
    • プラグインのインストールや、Wordpress自体の更新をWebから出来るので便利だが、クラックされたら、バックドアを仕掛けられまくって大変!
  • WordPressサイトを10個ぐらい運用しているので、手動で更新が大変だった。
  • 記事投稿に必要なuploadsディレクトリだけをwritableにして、プラグインとWordpressを最新状態にキープできるようにする。

インストール

Mac OSの場合は以下。

% brew install wp

その他の場合はこちらの手順でインストールを。
http://wp-cli.org/

スクリプト

これを、cronで1日1回とか動かせば、Wordpress本体、プラグイン、テーマを自動的に最新にできる。

#!/bin/zsh
# -------------------------------------
# Usage: % ./wordpress_update.sh
# Author: Yuki Matsukura
# -------------------------------------

# to be strict syntax checker
set -e

# set low priority
renice -n 19 $

WPS=(
  "/path/to/wordpress1/"
  "/path/to/wordpress2/"
)

for i in $WPS
do
  echo "Processing: $i"
  cd $i

  echo "Upgrading plugins."
  wp plugin update --all

  echo "Upgrading themes."
  wp theme update --all

  echo "Upgrading WordPress."
  wp core update && wp core update-db
done
Shell script to keep updated wordpress core and plugins.
Shell script to keep updated wordpress core and plugins. - wordpress_update.sh

コメント