Skip to content

Instantly share code, notes, and snippets.

@allysonsouza
Last active August 22, 2018 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allysonsouza/6cf842f64e8f772c89f5c589ad53df3c to your computer and use it in GitHub Desktop.
Save allysonsouza/6cf842f64e8f772c89f5c589ad53df3c to your computer and use it in GitHub Desktop.
Connect to your server trough ssh and run wp-cli commands in an automated way in Windows
:: Name: db-update.bat
:: Purpose: Connect to server trough ssh and run wp-cli commands
:: Author: @allysonsouza
:: URL: https://github.com/allysonsouza
:: Version: 0.0.1
:: License: GPL-v2
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:: variables
SET hostname=hostname.com.br
SET user=username
:: commands
SET command1=cd mydir/subdir
SET command2=wp config create --dbname=wpdb --dbuser=wpdbuser --dbpass=MyPass --dbhost=my.databasehost.com
SET command3=wp db import db/db.sql
SET command4=wp search-replace localhost www.mydomain.com.br
ECHO %CMDCMDLINE% | FINDSTR /L %COMSPEC% >NUL 2>&1
IF %ERRORLEVEL% == 0 SET interactive=1
:: ssh connect
ssh %user%@%hostname% "%command1% && %command2% && %command3% && %command4%"
IF "%interactive%"=="0" PAUSE
EXIT /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment