0

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;

https://dwaves.de/2022/07/09/gnu-linux-vm-dedicated-server-webserver-how-to-automate-bash-terminal-automate-wordpress-updates-core-plugins-themes-and-enhance-security/

1 Answer 1

0

I expect the problem relates to you using "su"

I believe an appropriate solution is to use "sudo" rather then "su". I use something a little similar to the following invocation -

sudo -u www-data /path/to/wp "add wp parameters here" 

This probably also negates the questionable "usermod -s /bin/bash www-data" line at the top of the script. (In my invocation, I don't even have valid users - I just use UIDs )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .