Skip to content

Instantly share code, notes, and snippets.

@trepmal
Last active August 29, 2015 14:12
Show Gist options
  • Save trepmal/8ca5291a85b4625ef20b to your computer and use it in GitHub Desktop.
Save trepmal/8ca5291a85b4625ef20b to your computer and use it in GitHub Desktop.
use wp-cli to verify core integrity, notify hipchat room on failure
#!/bin/sh
#
# cron ex:
# */15 * * * * cd /var/www/html/wordpress; verify-checksums
#
from='Alert'
room_id='HipChat Room Name/ID'
api_key='HipChat API Key'
wd=`pwd`
hn=`hostname`
wd="($hn) $wd"
# Quick check
wp core verify-checksums --no-color &> /dev/null
status=${PIPESTATUS[0]}
if [ "$status" = "0" ]
then
# PASSED! bail
exit
fi
# Didn't pass? Try again, just in case. And get more info for error output
wp core verify-checksums --no-color &> ./.out.txt
status=${PIPESTATUS[0]}
sed -i "/^Error/d" ./.out.txt; cat ./.out.txt
out=`cat ./.out.txt`
rm -f ./.out.txt
if [ "$status" = "0" ]
then
# PASSED! bail
exit
fi
# Welp, I guess something it wrong
message="$wd failed verify-checksums.
$out"
# echo $message
curl -d room_id="$room_id" -d from="$from" -d message="$message" -d color='purple' -d message_format='text' "https://api.hipchat.com/v1/rooms/message?format=json&auth_token=${api_key}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment