BASH script to email if WordPress plugins or themes need updating

This one took me all day. But I got it. I wanted to have a script that could look through all WordPress sites and find if there are outdated themes or plugins. All I need to do is slap it into a cron job and I am good to go!

Here is the BASH code to do it.

 

UPDATESNEEDED=""

for installpath in $(find /var/www -name wp-config.php)
do
cd $(dirname $installpath)

THEMENEEDED=$(php -r 'require_once("./wp-load.php");
delete_site_transient("update_themes");
wp_update_themes();
$new = get_site_transient("update_themes");
echo count($new->response);')

if [ ! $THEMENEEDED = 0 ]; then
UPDATESNEEDED="$UPDATESNEEDED \n Site $installpath needs $THEMENEEDED theme(s) updated"
fi

PLUGSNEEDED=$(php -r 'require_once("./wp-load.php");
delete_site_transient("update_plugins");
wp_update_plugins();
$new = get_site_transient("update_plugins");
echo count($new->response);')

if [ ! $PLUGSNEEDED = 0 ]; then
UPDATESNEEDED="$UPDATESNEEDED \n Site $installpath needs $PLUGSNEEDED plugin(s) updated"
fi
done

if [ -n "$UPDATESNEEDED" ]; then
echo -e "$UPDATESNEEDED" | mail -s "Updates are needed" email@company.com
fi

I have been needing this script for a while.

,

3 Responses to BASH script to email if WordPress plugins or themes need updating

  1. Michael Kleinert September 17, 2011 at 2:13 pm #

    What a great find! Nice job!

    Thanks very much for writing this and posting it, Jeffrey.

    For anybody else who stumbles onto this page, it should be noted that you will want to change line 3 for a cpanel server to the following to reflect the proper server path for user account directories –

    > for installpath in $(find /home -name wp-config.php)

    Jeffrey – It looks like it ran successfullly for me, but it did complain a bit while executing – any insight on the cause of the errors shown below?

    Thanks again!

    Mike

    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments
    ./wordpress-check: line 13: [: too many arguments
    ./wordpress-check: line 21: [: too many arguments

  2. jbmurphy September 19, 2011 at 3:16 pm #

    Not sure what the error is, let me know what line 13 and 21 in your script are. Those line number may not correlate with my line numbers.

Trackbacks/Pingbacks

  1. BASH script to email if WordPress plugins or themes need updating … | Linux Blog - August 18, 2011

    […] a cron job and I am good to go! Here is the BASH code to do it. … See original here: BASH script to email if WordPress plugins or themes need updating … This entry was posted in Uncategorized and tagged bash, cron-job, look-through by admin. Bookmark […]

Powered by WordPress. Designed by WooThemes