Skip to main content

Wordpress cli via cron - user/path issues

Comments

4 comments

  • cPRex Jurassic Moderator
    Hey there! Just to confirm, if you run this on the command line directly, it works as expected? /usr/local/bin/wp post create --post_type=post --post_title='test 123' --post_status=publish --path=/home/development/public_html/ > /home/development/cron.txt
    I believe you'll need to specify the path of PHP, and possibly the WordPress install too: /usr/bin/ea-php## /usr/local/bin/wp --path=/home/username/public_html/ post create --post_type=post --post_title='test 123' --post_status=publish --path=/home/development/public_html/ > /home/development/cron.txt
    Can you try that and see if that gives you better results? You'll just need to adjust the "##" portion to use the version of PHP you're working with.
    0
  • jk_gabba
    yes, the command works correctly via terminal every time, and i've just tried via cron with the php version as you suggest and it gives the same result, it runs and obviously finds php but rather than executing the command it just spits out the default wp info text, which suggests that wp-cli works as it should but its just not being directed at the wordpress install or responding to the path value. wondered if it was cron user related, or due to not exectuing in the correct directory, so i tried this: cd /home/development/public_html; /usr/bin/ea-php81 /usr/local/bin/wp post create --post_type=post --post_title='test 444' --post_status=publish --path=/home/development/public_html/ > /home/development/cron.txt and that does the same, just spits out the info.
    0
  • cPRex Jurassic Moderator
    Could you submit a ticket to our team so we can take a look?
    0
  • rbairwell
    cd /home/development/public_html; /usr/bin/ea-php81 /usr/local/bin/wp post create --post_type=post --post_title='test 444' --post_status=publish --path=/home/development/public_html/ > /home/development/cron.txt and that does the same, just spits out the info.

    Can you try something like cd /home/development/public_html && /usr/local/bin/php /home/development/bin/wp post create --post_type=post --post_title='test 444' --post_status=publish >> /home/development/cron.txt[ 2>&1
    The &&
    (Bash's logical "and") can help chain commands - the semicolon indicates to Bash that they are separate commands and so the cd
    command may not affect effect the next call. Adding the 2>&1
    to the end will also mean any error output (on stderr/pipe 2) will go into your cron.txt log.
    0

Please sign in to leave a comment.