WP-CLI: STDOUT error when called in CRON (crontab) - wp-cli

Little help or guidance. Server is CentOS 7 - with WHM/CPanel installed.
Command:
$(which php) $(which wp) core update --require=/opt/wp-cli-pre.php --path=/home/USER/public_html/
The contents of /opt/wp-cli-pre.php
<?php
if(!defined('STDIN')) define('STDIN', fopen('php://stdin', 'r'));
if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'w'));
if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'w'));
Works as expected from the command line, but if from cron job, I get:
PHP Warning: Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/utils.php on line 1057
output of "which php"
/usr/local/bin/php
output of "which wp"
/usr/local/bin/wp
I have installed the latest WP-CLI from https://wp-cli.org/

At long last, I have found the solution.
When the CRON runs a PHP script like this: */5 * * * * php /path/to/script.php
The SAPI name is: cgi-fcgi (on a WHM/CPanel install on CentOS)
It cannot find the CLI version setup by CPanel at /usr/local/bin/php as the $PATH var is just: /usr/bin:/bin
So, the solution is to not depend on the system environment to determine the PHP you want. But to set that directly.
Like this: */5 * * * * /usr/local/bin/php /path/to/script.php
It was always my assumption that if a CRON was setup in ROOT's crontab, it would inherit ROOT's environment. This apparently is not the case.

You should take a look at the following post.
https://forums.cpanel.net/threads/users-cannot-use-wp-cli-in-cron.643293/

Related

How can i add a cron job run every minute to my elearning site on moodle?

I try to add a cron job on an elearning.mysite.gr(Moodle). Although my host gives this message every hour.
Oct 2 1:10:01 linux CROND[123456]: (admin) CMD (touch /tmp/test.txt > /dev/null)
On my site administration -> notifications get this message:
The admin/cli/cron.php script has not been run for 3 days 2 hours and should run every 1 min.
At moodle documentation
/path/to/moodle/admin/cli/cron.php, can i use it ? in which way ?
I tried this :
/usr/bin/php /path/to/moodle/admin/cli/cron.php
but gives me that the process completed with error at one minute
only this touch /tmp/test.txt > /dev/null
completed with success.
Moodle Documentation:
The CLI (command line interpreter) script. This will be at the path /path/to/moodle/admin/cli/cron.php
If in doubt, this is the correct script to use. This needs to be run by a 'PHP CLI' program on your computer. So the final command may look something like /usr/bin/php /path/to/moodle/admin/cli/cron.php You can (and should) try this on your command line to see if it works. WARNING: Check your command-line PHP version is compatible with your chosen version of Moodle.-How to check it?
The command-line PHP program is different to the one running your web site and is not always the same version.
I don't know what to do...I will appreciate any help!!!
I tried by my host panel interface :
Type of progress:
Command line
URL
PHP
i should choose one from 3.
Command*:
placeholder to add my command to be excecuted
Excecute:
Dropdown
1.Cron style
2.Daily at 00:00
I use command line.
touch /tmp/test.txt
When i add
cron style and 1 * * * * * , get message for syntax.
and for
daily at 00:00 success message but on my notification of my site has
The admin/cli/cron.php script has not been run for 17 days 22 hours and should run every 1 min.
That's the icon of my Plesk Login. To change the path/to/moodle/admin/cli/cron.php xould i check the file manager in order to find cron.php file ??
As you add the cron from a web interface (maybe Plesk ?) you only need this part:
/path/to/moodle/admin/cli/cron.php
replace /path/to/moodle/ with the real path on your server, usulay something like /var/www/moodle/ or /var/www/vhosts/domain.name/httpdocs/moodle
To run every 1 minute cron style is :
* * * * *
If you can choose PHP version, choose the same version as the one you are using for Moodle.
Finally, I give this touch /tmp/test.txt ->and at cron style the touch /tmp/test.txt, as you suggest to me.
Because the other commands cannot complete with success.
But in my notifications,(Site administration-Moodle) i still get the message that cron don't run.

Where is the Magento 2 update/cron.php file supposed to come from?

I have installed Magento 2 using the instructions in the development documentation.
Everything works fine except for the cron jobs that the admin system continually says are not working.
I followed the development docs and added the following lines into my crontabs file.
*/1 * * * * php -c /etc/php5/cli/apache2 /var/www/html/magento2/bin/magento cron:run
*/1 * * * * php -c /etc/php5/cli/apache2 /var/www/html/magento2/update/cron.php
*/1 * * * * php -c /etc/php5/cli/apache2 /var/www/html/magento2/bin/magento setup:cron:run
I have manually run the first and third command and they run without error. The second line I am having problems with. /var/www/html/magento2/update/cron.php does not exist. In fact the update directory does not exist.
Where does the update directory come from, and why don't I have it?
update/cron.php file is in the magento2-community-edition package:
https://github.com/magento/magento2-community-edition/blob/2.0.0/update/cron.php

EclipseFP issues with Hoogle

Installed EclipseFP, looks without any observable issues. However, when I start Eclipse, I get this:
Whether I click yes or no, the same thing happens on next restart.
Also, in the Hoogle view, I see this:
even though I see the databases seemingly OK in workspace\.metadata\.plugins\net.sf.eclipsefp.haskell.browser\scion-browser-0.2-dbs:
hackage.db 123.71 MB 31.10.2014 09:42:18 Data Base File A
local.db 3.06 MB 31.10.2014 10:20:53 Data Base File A
In the scion-browser console, I have this on startup:
>> {"rebuild":true,"filepath":"C:\\eclipse\\workspace\\.metadata\\.plugins\\net.sf.eclipsefp.haskell.browser\\scion-browser-0.2-dbs\\local.db","command":"load-local-db"}
Local database loaded
"ok"
>> {"module":"","command":"get-modules","db":"_all"}
>> {"rebuild":false,"filepath":"C:\\eclipse\\workspace\\.metadata\\.plugins\\net.sf.eclipsefp.haskell.browser\\scion-browser-0.2-dbs\\hackage.db","command":"load-hackage-db"}
Hackage databas"ok"
e loaded
>> {"module":"Prelude","command":"get-declarations","db":"_all"}
>> {"path":"C:\\eclipse\\workspace\\.metadata\\.plugins\\net.sf.eclipsefp.haskell.ui\\sandbox\\.cabal-sandbox\\bin\\hoogle.exe","command":"extra-hoogle-path"}
"ok"
>> {"command":"hoogle-check"}
C:\eclipse\workspace\.metadata\.plugins\net.sf.eclipsefp.haskell.ui\sandbox\.cabal-sandbox\bin\hoogle.exe
"Error"
Looks like hoogle is not working from the command line either:
C:\>cd C:\eclipse\workspace\.metadata\.plugins\net.sf.eclipsefp.haskell.ui\sandbox\.cabal-sandbox\bin\
C:\eclipse\workspace\.metadata\.plugins\net.sf.eclipsefp.haskell.ui\sandbox\.cabal-sandbox\bin>hoogle fmap
Could not find some databases: default
Searching in:
.
C:\eclipse\workspace\.metadata\.plugins\net.sf.eclipsefp.haskell.ui\sandbox\.cabal-sandbox\x86_64-windows-ghc-7.8.3\hoogle-4.2.36\databases
There are no available databases, generate them with: hoogle data
C:\eclipse\workspace\.metadata\.plugins\net.sf.eclipsefp.haskell.ui\sandbox\.cabal-sandbox\bin>
Any ideas here? I'll add additional information as needed, just not sure what would be useful, let me know and I'll edit.
Looks like for some reason hoogle did not work from the command line either. May be related to this:
C:\eclipse\workspace\.metadata\.plugins\net.sf.eclipsefp.haskell.ui\sandbox\.cabal-sandbox\bin>hoogle data
Downloading downloads/platform.cabal
WARNING: Could not find command line program wget.
You may be able to install it from:
http://gnuwin32.sourceforge.net/packages/wget.htm
WARNING: Could not find command line program curl.
You may be able to install it from:
http://curl.haxx.se/download.html
hoogle: Error when running Shake build system:
* default.hoo
* platform.hoo
* platform.txt
* downloads/platform.cabal.cache
* downloads/platform.cabal
Could not find downloader, neither curl nor wget are on the $PATH.
I have Cygwin installed, so I fixed this by running hoogle data from withing Cygwin terminal, which had wget available in the path and that seems to have solved the issue.

Where to find logs for a cloud-init user-data script?

I'm initializing spot instances running a derivative of the standard Ubuntu 13.04 AMI by pasting a shell script into the user-data field.
This works. The script runs. But it's difficult to debug because I can't figure out where the output of the script is being logged, if anywhere.
I've looked in /var/log/cloud-init.log, which seems to contain a bunch of stuff that would be relevant to debugging cloud-init, itself, but nothing about my script. I grepped in /var/log and found nothing.
Is there something special I have to do to turn logging on?
The default location for cloud init user data is already /var/log/cloud-init-output.log, in AWS, DigitalOcean and most other cloud providers. You don't need to set up any additional logging to see the output.
You could create a cloud-config file (with "#cloud-config" at the top) for your userdata, use runcmd to call the script, and then enable output logging like this:
output: {all: '| tee -a /var/log/cloud-init-output.log'}
so I tried to replicate your problem. Usually I work in Cloud Config and therefore I just created a simple test user-data script like this:
#!/bin/sh
echo "Hello World. The time is now $(date -R)!" | tee /root/output.txt
echo "I am out of the output file...somewhere?"
yum search git # just for fun
ls
exit 0
Notice that, with CloudInit shell scripts, the user-data "will be executed at rc.local-like level during first boot. rc.local-like means 'very late in the boot sequence'"
After logging in into my instance (a Scientific Linux machine) I first went to /var/log/boot.log and there I found:
Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200! I am
out of the file. Log file somewhere? Loaded plugins: changelog,
kernel-module, priorities, protectbase, security,
: tsflags, versionlock 126 packages excluded due to repository priority protections 9 packages excluded due to repository
protections ^Mepel/pkgtags
| 581 kB 00:00
=============================== N/S Matched: git =============================== ^[[1mGit^[[0;10mPython.noarch : Python ^[[1mGit^[[0;10m Library c^[[1mgit^[[0;10m.x86_64 : A fast web
interface for ^[[1mgit^[[0;10m
...
... (more yum search output)
...
bin etc lib lost+found mnt proc sbin srv tmp var
boot dev home lib64 media opt root selinux sys usr
(other unrelated stuff)
So, as you can see, my script ran and was rightly logged.
Also, as expected, I had my forced log 'output.txt' in /root/output.txt with the content:
Hello World. The time is now Wed, 11 Sep 2013 10:21:37 +0200!
So...I am not really sure what is happening in you script.
Make sure you're exiting the script with
exit 0 #or some other code
If it still doesn't work, you should provide more info, like your script, your boot.log, your /etc/rc.local, and your cloudinit.log.
btw: what is your cloudinit version?

Foreman start fails on Windows following Heroku tutorial

I'm following the heroku tutorial for Heroku/Facebook integration (but I suspect this issue has nothing to do with facebook integration) and I got stuck on the stage where I was supposed to start foreman (I've installed the Heroku installbelt for windows, which includes foreman):
> foreman start
gives:
C:/RailsInstaller/Ruby1.8.7/lib/ruby/site_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find foreman (>= 0) amongst [POpen4-0.1.4, Platform-0.4.0, ZenTest-4.6.2, abstract-1.0.0, actionm
ailer-3.0.11, actionmailer-3.0.9, actionpack-3.0.11, actionpack-3.0.9, activemodel-3.0.11, activemodel-3.0.9, activerecord-3.0.11, activerecord-3.0.9, activerecord-sqlserver-adapter-3.0.15, activereso
urce-3.0.11, activeresource-3.0.9, activesupport-3.0.11, activesupport-3.0.9, addressable-2.2.6, annotate-2.4.0, arel-2.0.10, autotest-4.4.6, autotest-growl-0.2.16, autotest-rails-pure-4.1.2, autotest
-standalone-4.5.8, builder-2.1.2, bundler-1.0.15, diff-lcs-1.1.3, erubis-2.6.6, factory_girl-1.3.3, factory_girl_rails-1.0, faker-0.3.1, gravatar_image_tag-1.0.0.pre2, heroku-2.14.0, i18n-0.5.0, json-
1.6.1, launchy-2.0.5, mail-2.2.19, mime-types-1.17.2, mime-types-1.16, nokogiri-1.5.0-x86-mingw32, open4-1.1.0, pg-0.11.0-x86-mingw32, polyglot-0.3.3, polyglot-0.3.1, rack-1.2.4, rack-1.2.3, rack-moun
t-0.6.14, rack-test-0.5.7, rails-3.0.11, rails-3.0.9, railties-3.0.11, railties-3.0.9, rake-0.9.2.2, rake-0.8.7, rb-readline-0.4.0, rdoc-3.11, rdoc-3.8, rest-client-1.6.7, rspec-2.6.0, rspec-core-2.6.
4, rspec-expectations-2.6.0, rspec-mocks-2.6.0, rspec-rails-2.6.1, rubygems-update-1.8.11, rubyzip-0.9.4, rubyzip2-2.0.1, spork-0.9.0.rc8-x86-mingw32, sqlite3-1.3.3-x86-mingw32, sqlite3-ruby-1.3.3, te
rm-ansicolor-1.0.7, thor-0.14.6, tiny_tds-0.4.5-x86-mingw32, treetop-1.4.10, treetop-1.4.9, tzinfo-0.3.31, tzinfo-0.3.29, webrat-0.7.1, will_paginate-3.0.pre2, win32-api-1.4.8-x86-mingw32, win32-open3
-0.3.2-x86-mingw32, win32-process-0.6.5, windows-api-0.4.0, windows-pr-1.2.1, zip-2.0.2] (Gem::LoadError)
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/site_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
from C:/RailsInstaller/Ruby1.8.7/lib/ruby/site_ruby/1.8/rubygems.rb:1210:in `gem'
from C:/Program Files (x86)/ruby-1.9.3/bin/foreman:18
Since I'm a complete noob in this I'm not sure if my question here is a duplicate for Error on 'foreman start' while following the Python/Flask Heroku tutorial (because it's not quite the same error). If so, does anyone have a method for deploying a development environment on windows (for Heruko, Python, Facebook app)? Or should I use Ubuntu for this?
Thanks
Although this question doesn't seem to be of interest to anyone here (5 views in ~2 hours, 0 answers, 0 comments...), I have found the solution and ready to share it with anyone that will encounter it:
Install the latest ruby from rubyinstaller.org (1.9.3-p194) - Sometimes there is a collision installs of the same version, in my case I've just uninstalled all versions of ruby, but if you already have other application that needs older version then you have to be more careful
Check that your system is default to use this version by invoking ruby -v in command line prompt: and getting ruby 1.9.3p194 (2012-04-20) [i386-mingw32] (you may have to close and re-open cmd, to include the new environment variables)
Still in cmd, invoke:
gem install foreman
gem install taps
now go to your Procfile app (e.g. your heroku example app from the tutorial) and execute foreman start, you should see something like this:
18:23:52 web.1 | started with pid 7212
18:23:54 web.1 | * Running on http://0.0.0.0:5000/
18:23:54 web.1 | * Restarting with reloader
after manually adding the ruby path to my system PATH environment variable (Win 7), it still didn't work.
i had to change the default install path of Heroku from
C:\Program Files(x86)\Heroku
to
C:\Heroku
as it didn't properly handle the space in the path. I also tried C:\PROGRA~2\Heroku\ruby-1.9.2\bin to no avail. I imagine any space-less path will do.
hth