我有一个 bash 脚本,它从我的数据库中检索信息,根据它获得的信息创建一些文件夹,每个文件夹包含 WP 文件,然后进行设置。当我手动调用该脚本时,它运行良好,但是当从我的 ubuntu Cronjob 调用时,WP CLI 不起作用
以下是 Bash 脚本:
#!/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
这是 cronjob(以 root 身份运行)
* * * * * /bin/bash /home/iosef/createinstanceinfolder.sh >/dev/null 2>&1
任何想法?
答案1
用户 9517 提供了答案:这回答了你的问题吗?为什么我的 crontab 不起作用,我该如何排除故障? –