-1

I have a bash script which is retrieving the information from my database, based on the information it gets creates some folders containing the WP files on each one and then makes the setting. The script works perfect when I call it manually however the WP CLI dosent work when is called from my ubuntu Cronjob

Here is the bash script:

#!/bin/bash 

set -f        # disable globbing
IFS=$'\n'     # set field separator to NL (only)



arr=($(sudo mysql -u root -h localhost  -e "USE mysite;SELECT * FROM sites WHERE status = 'pending'" | awk 'NR>1'))



for i in "${arr[@]}"
do
siteid=$(echo $i | awk '{print $1}')
instance=$(echo $i | awk '{print $2}')
owner=$(echo $i | awk '{print $3}')
status=$(echo $i | awk '{print $4}')
temporaryurl=$(echo $i | awk '{print $5}')
url=$(echo $i | awk '{print $6}')
dbname=$(echo $i | awk '{print $7}')
dbuser=$(echo $i | awk '{print $8}')
dbpass=$(echo $i | awk '{print $9}')
dbprefix=$(echo $i | awk '{print $10}')
title=$(echo $i | awk '{print $11}')
admin_user=$(echo $i | awk '{print $12}')
admin_password=$(echo $i | awk '{print $13}')
admin_email=$(echo $i | awk '{print $14}')

sudo mysql -u root -h localhost  -e "CREATE database $url;GRANT all privileges on $url.* to $dbuser@'localhost' identified by '$dbpass'"

sudo cp -r /var/www/mysite.com/wordpressfiles /var/www/mysite.com/$url

sudo chown iosef:iosef -R /var/www/mysite.com/$url
sudo find /var/www/mysite.com/$url -type d -exec chmod 777 {} \;
sudo find /var/www/mysite.com/$url -type f -exec chmod 777 {} \;
sudo find /var/www/mysite.com/$url/wp-content/ -type d -exec chmod 777 {} \;
sudo find /var/www/mysite.com/$url/wp-content/ -type f -exec chmod 777 {} \;


cd /var/www/mysite.com/$url && /usr/local/bin/wp core config --dbname=$url --dbuser=$dbuser --dbpass=$dbpass --dbprefix=$dbprefix;

cd /var/www/mysite.com/$url && /usr/local/bin/wp core install --url=www.mysite.com/$url --title=$title --admin_user=$admin_user --admin_password=$admin_password --admin_email=$admin_email;


done

And here is the cronjob (is runned as root)

* * * * * /bin/bash /home/iosef/createinstanceinfolder.sh >/dev/null 2>&1

Any idea?

vautee
  • 470
  • 3
  • 11
Iosef
  • 1
  • Is there any error output from your cron job in /var/log/syslog? Maybe remove the >/dev/null 2>&1 part so you'll see any errors that show up. Add them to your question. – vautee Jan 15 '22 at 21:36
  • The duplicate will almost certainly help you to solve your problem, If it does not it will help you gather information that will help people to help you. – user9517 Jan 15 '22 at 21:48
  • Now Im getting the error, says this: Error: YIKES! It looks like you're running this as root. You probably meant to run this as the user that your WordPress installation exists under. If you REALLY mean to run this as root, we won't stop you, but just bear in mind that any code on this site will then have full control of your server, making it quite DANGEROUS. – Iosef Jan 15 '22 at 22:47
  • If you'd like to continue as root, please run this again, adding this flag: --allow-root If you'd like to run it as the user that this site is under, you can run the following to become the respective user: sudo -u USER -i -- wp – Iosef Jan 15 '22 at 22:48

1 Answers1

0

user9517 provided the answer: Does this answer your question? Why is my crontab not working, and how can I troubleshoot it? –

Iosef
  • 1