Skip to content

Instantly share code, notes, and snippets.

@MattRyanCo
Last active September 16, 2018 21:49
Show Gist options
  • Save MattRyanCo/69b6a8dc1bcb7256d14f8ed1a079146e to your computer and use it in GitHub Desktop.
Save MattRyanCo/69b6a8dc1bcb7256d14f8ed1a079146e to your computer and use it in GitHub Desktop.
shell script to run through all MainWP sites performing security scan
# cd into the root of your MainWP dashboard site
# Note: your wordpress install may be at a different location on your web host
# This example is an apache host where I ssh into the root of the server
cd ../var/www/html
# run wp-cli command to list all your MainWP child sites
wp mainwp sites
# output looks like this (withou the # symbol - that is a comment indicator)
#+----+---------------------------+------------------------+---------+
#| id | name | url | version |
#+----+---------------------------+------------------------+---------+
#| 6 | site6.com | http://site6.com/ | 3.4.9 |
#| 17 | site17.com | https://site17.com/ | 3.4.9 |
#| 2 | site2.com | https://site2.com/ | 3.4.9 |
#| 16 | site16.com | https://site16.com/ | 3.4.9 |
#| 11 | site11.com | https://site11.com/ | 3.4.9 |
#| 4 | site4.com | https://site4.com/ | 3.4.9 |
#| 1 | site1.com | https://site1.com/ | 3.4.9 |
#| 13 | site13.com | https://site13.com/ | 3.4.9 |
#| 5 | site5.com | https://site5.com/ | 3.4.9 |
#| 8 | site8.com | https://site8.com/ | 3.4.9 |
#| 3 | site3.com | https://site3.com/ | 3.4.9 |
#| 7 | site7.com | https://site7.com/ | 3.4.9 |
#| 14 | site14.com | http://site14.com/ | 3.4.9 |
#| 18 | site18.com | http://site18.com/ | 3.4.9 |
#| 10 | site10.com | https://site10.com/ | 3.4.9 |
#+----+---------------------------+-----------------------------------
#
# to process all my sites I build a loop that tracks trough each site
# by number. Fo each site it will run the command
# wp mainwp-sucuri scan <site number> where
# <site number> is repalce by each number in the list.
# When entering the loop at the command line in the BASH shell your
# Unix host will/should respond with the > symbol indicating it is
# expecting the script to continue with another command
# When the BASH shell sends the 'done' command the loop os executed.
for i in 1 3 4 5 7 8 11 13 14 16 17 18
> do
> wp mainwp-sucuri scan $i
> done
# This will cycle through all of the listed sites running the Sucuri Scan.
# Check the security scan tab on the Manage Sites page
# MainWP › Sites › site1.com › Security Scan
#
# To run the sucuri scan on one or two sites, enter the
# scan command with only a single site number like so:
# wp mainwp-sucuri scan 1
# wp mainwp-sucuri scan 2
@MattRyanCo
Copy link
Author

Working on automating this.
Plan to run the output of the wp mainwp sites command into a temp file,

wp mainwp sites > testfile

Next to run the formatted output through a grep / awk / cut with the correct regex to generate the listing of site numbers alone.

Almost there with these regex's

  1. "^| \d{1,2} -works in regex tester, not in bash
  2. cut -c3-4 textfile | grep -E "^| [0-9]{1,2}|"

The next iteration would only run the scan on site that have not been scanned in x days.

@MattRyanCo
Copy link
Author

Update:

Commented out documentation lines and added instructions.
All lines preceded by a '#' are comments and are not executed by the command processor on the host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment