this script is run by update.sh wich is run by cron every day at 2 o'clock, it allows wordpress to be updated automatically via cli (needs to be installed before) actually runs fine, when run as root
but it fails when run via cron
with the error
=== updating /var/www/html/domain.com ===
currently installed:
This account is currently not available <- which means, despite allowing www-data to temporarily log in, it can not.
..... if updates available, updating:
...core
This account is currently not available.
...themes
This account is currently not available.
...plugins
This account is currently not available.
which means: despite allowing www-data to temporarily log in like this:
usermod -s /bin/bash www-data
it can not, when run as cron job.
Why?
vim /root/scripts/wordpress_update.sh
#!/bin/bash
# what to backup
WEBROOT=/var/www/html
# temporarily allow non-root apache2 user to login
usermod -s /bin/bash www-data
echo "===== wordpress automatic update single wordpress in web root ===="
INSTALLATION=$WEBROOT
echo "currently installed:";
su www-data -c "wp core version --path=$INSTALLATION";
echo "..... if updates available, updating:"
echo "...core"; su www-data -c "wp core update --path=$INSTALLATION";
echo "...themes"; su www-data -c "wp theme update --all --path=$INSTALLATION";
echo "...plugins"; su www-data -c "wp plugin update --all --path=$INSTALLATION";
# echo "===== wordperss automatic update multiple wordpress in web root ====="
# for FULLPATH in $WEBROOT/*; do
# if [ -d "$FULLPATH" ]; then
# BASENAME=$(basename $FULLPATH);
#
# INSTALLATION=$FULLPATH;
# # might need modification like this:
# # INSTALLATION=$FULLPATH/public_html;
#
# echo "=== updating $INSTALLATION ==="
# echo "currently installed:"; su www-data -c "wp core version --path=$INSTALLATION";
# echo "..... if updates available, updating:"
# echo "...core"; su www-data -c "wp core update --path=$INSTALLATION";
# echo "...themes"; su www-data -c "wp theme update --all --path=$INSTALLATION";
# echo "...plugins"; su www-data -c "wp plugin update --all --path=$INSTALLATION";
# fi
# done
# disable login again for non-root apache2 default user
usermod -s /sbin/nologin www-data
echo "=== disable xmlrpc.php because a lot of pwd brute force attacks focus on this file ==="
echo "... also via the readme.html the installed version of wordpress can be identified"
echo "... the following files were found and renamed to .disabled"
find $WEBROOT -type f -name 'xmlrpc.php';
find $WEBROOT -type f -name 'xmlrpc.php' -print0 | xargs --null -I{} mv {} {}.disabled;
find $WEBROOT -type f -name 'liesmich.html';
find $WEBROOT -type f -name 'liesmich.html' -print0 | xargs --null -I{} mv {} {}.disabled;
find $WEBROOT -type f -name 'readme.html';
find $WEBROOT -type f -name 'readme.html' -print0 | xargs --null -I{} mv {} {}.disabled;
find $WEBROOT -type f -name 'license.txt';
find $WEBROOT -type f -name 'license.txt' -print0 | xargs --null -I{} mv {} {}.disabled;