Script runned by crontab will no produce data - php

Using Cacti, I'm trying to run the following command:
php poller.php > test.cfg
As expected I'm getting the following output :
root#SLINUX01:[/usr/local/cacti]$tail -f test.cfg
Waiting on 1 of 1 pollers.
Waiting on 1 of 1 pollers.
Waiting on 1 of 1 pollers.
Waiting on 1 of 1 pollers.
05/12/2016 01:23:50 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /usr/local/cacti/rra/stse01_traffic_in_14.rrd --template traffic_out:traffic_in 1463052230:2773678063:3900704413
05/12/2016 01:23:50 PM - POLLER: Poller[0] CACTI2RRD: /usr/bin/rrdtool update /usr/local/cacti/rra/stse01_traffic_in_15.rrd --template traffic_in:traffic_out 1463052230:1071486:1088742
05/12/2016 01:23:50 PM - SYSTEM STATS: Time:5.4128 Method:cmd.php Processes:1 Threads:N/A Hosts:3 HostsPerProcess:3 DataSources:9 RRDsProcessed:7
Loop Time is: 5.41
Sleep Time is: 294.58
Total Time is: 5.42
^C
And my manipulated has updated.
Now using the crontab, I made the following :
*/5 * * * * cacti php /usr/local/cacti/poller.php > /home/cacti/test.cfg &>/home/cacti/test.cfg
But when i go in the /home/cacti/test.cfg after cron execution , I got nothing, but the cron runned the script :
May 12 15:25:01 SLINUX01 CROND[19871]: (root) CMD (cacti php /usr/local/cacti/poller.php > /home/cacti/test.cfg &>/home/cacti/test.cfg)
What is the source of this problem?
Thanks in advance.

Your cron log entry only says that the command was tried. It does not guarantee that the command has been successfully started (permission problems? environment variables unset? unmounted filesystem?).
Do you use the cron table for the same user that can successfully run the command from command-line?
What are the exact paths when you run from command line?
Note that in crontab you try to invoke php without giving its full path - that may well be the culprit.

Related

PHP cron job does not execute only if I manually execute via cli

I have a cron job set up to write a local json file. It should run every hour and over write
previous file. but it is not running unless I run it manually via the cli. Here is how i have set up on the crontab
00 * * * * php /var/www/cron_jobs/pixel_mapping.php >/dev/null 2>&1
the permissions of the php file are
rw-rw-r-- 1 username username 822 Apr 13 11:02 pixel_mapping.php
my user permissions are
drwxrwxr-x
If I run it as php /var/www/cron_jobs/pixel_mapping.php on the cli
it does write to the json file. any ideas or trouble shooting ideas to try and
have this done by the cron?
many thanks

Cron is not executing files

I have a php file to execute every minute but when I am running it on command line it executes as expected, but when set to cron job it does not run. Below mentioned are things which I have checked:
cron service
service crond status
crond (pid 183872) is running...
Checked logs of cron execution :
May 21 00:27:01 spartans CROND[194123]: (root) CMD (/usr/bin/php /home/dev/my.php)
May 21 00:27:01 e2e CROND[194122]: (root) MAIL (mailed 84 bytes of output but got status 0x004b#012)
CronJob list in crontab -e
*/1 * * * * /usr/bin/php /home/dev/my.php
My request is to help me in finding error where things are getting wrong. I have started cron service couple of times.

Magento 1.9.1 Cron Not Running

I am having big issues with the cron of Magento 1.9.1 hoping someone can help. I have AOE installed and see not heartbeat.
I have added my cron job
*/5 * * * * /bin/sh /var/sites/p/domain/public_html/cron.sh
But this still does not run, so I decided to try and try and run cron.php, this does nothing. This is my cron for this
*/5 * * * */usr/bin/wget -O /dev/null -o /dev/null http://www.domain.com/cron.php
Based on Magneto 1.8 cron.php I added the following to the cron.php.
$isShellDisabled = true;
Based on this still not working I tried the cron.php in the browser. I get an error in the browser that Printing is disabled by default for security reasons.
So I changed my php.ini to memory_limit = 512M just incase. This is still not working.
The error I get in my reports for this is:
a:5:{i:0;s:59:"Mage registry key "_singleton/cron/observer" already exists";i:1;s:537:"#0 /var/sites/p/domain.co.uk/public_html/app/Mage.php(223): Mage::throwException('Mage registry k...')
#1 /var/sites/p/domain.co.uk/public_html/app/Mage.php(477): Mage::register('_singleton/cron...', false)
#2 /var/sites/p/domain.co.uk/public_html/app/code/core/Mage/Core/Model/App.php(1316): Mage::getSingleton('cron/observer')
#3 /var/sites/p/domain.co.uk/public_html/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('default', Array)
#4 /var/sites/p/domain.co.uk/public_html/cron.php(74): Mage::dispatchEvent('default')
#5 {main}";s:3:"url";s:9:"/cron.php";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}
Any help would be really great.
Note ** I have change the domain name to DOMAIN due to my site not being suitable for work.
Few simple steps to fix Magento cron issue:
Go to System > Configuration > Advanced > System > Cron (Scheduled Tasks) and set next values:
Generate Schedules Every: 15
Schedule Ahead for: 20
Missed if Not Run Within: 15
History Cleanup Every: 10
Success History Lifetime: 60
Failure History Lifetime: 600
Clear Cache in System > Cache Management
Clear 'cron_schedule' table. You can do it via phpmyadmin or execute next command in SQL console:
TRUNCATE TABLE cron_schedule;
Add next line to cron settings (use absolute paths):
*/5 * * * * /usr/bin/php /absolute/path/on/your/server/to/file/cron.php
Note: in some configurations on webserver (apache/nginx) allowed to execute php scripts. In this case add this line to webserver's user crontab. Example for apache: crontab -u apache -e
Restart cron daemon.
Check table 'cron_schedule', if it's not empty - Magento cron script start working.
Well I've had a different issue. My cron was simply not working, although cron.php was executed properly. Still no output, and no jobs done.
I've checked cron_schedule and noticed that last job there is from 19th of March this year (sic!). So i kept on looking for cause.
Finally I've noticed that that there is process running with my cronjob from 19th of March (sic!).
josh 21350 99.6 0.4 350400 133492 ? R Mar19 241812:21 /usr/bin/php /var/www/mysite/cron.php -mdefault
I've killed the job with: kill -9 21350
And voila! Suddenly newsletter is being sent!
I had no idea why, and how this happened. Now i know i should pay attention to it, so I will.
I just saw that you are using magento 1.9.1.
Run the cron using php instead : /usr/local/bin/php -f /home/cpanel_username/public_html/cron.php
This should resolve http permission problems you might be having when using 'usr/bin/wget -O /dev/null -o /dev/null'
Try that command and let me know if it works for you.

Run PHP script with CRON

I try to run PHP scripts on my debian server, everyday at midnight & 1 minute.
So I created the crontab file in admin, with
crontab -e
who seems to be in
/tmp/crontab.ky3Q3F/crontab
And I put the line
01 00 * * * /usr/bin/php5 /var/www/MySite/cronTB.php
Bellow the comments.
The goal is to run cronTB.php (with PHP) everyday at 0h01.
Is my syntax correct ?
Is the correct file to edit, to the correct path ?
Is the CRON daemon still runing after I run it with:
/etc/init.d/cron start
even if I close the ssh connexion ?
Thanks for help

Cronjob php script not working

I'm trying to set a cronjob to run every 20 minutes.
This works manually:
php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php LONDON
I tried to use "crontab -e" and set it even to every 20 minutes with:
*/20 * * * * php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php LONDON
it was saved to /tmp/crontab.0xYhei9m/crontab
And it doesn't seem to work.
What's wrong here?
EDIT:
Current stats:
*. cron is up and running:
root 31855 1 0 08:39 ? 00:00:00 /usr/sbin/cron
*. Running "crontab -l" shows:
*/20 * * * * /usr/bin/php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php
LONDON
And still no go. Again manually running the script works just fine.
is the cron daemon even running?
it was saved to /tmp/crontab.0xYhei9m/crontab
Yes - that's the file you just edited - its NOT the file crond reads to fire jobs. Crontab whould then read this file, install the updated crontab in the location where crond looks for it and notify crond it needs to process the file.
Have you checked:
crond is running?
your uid is allowed to schedule cron jobs (usually via /etc/cron.allow / /etc/cron.deny)
that the script really isn't being started by cron and failing due to a permissions error?
that the version of crond you are using support $PATH and can find the executable?
In case this is already online, try using wget instead of php, with the url instead of the path, ie.:
*/20 * * * * wget http://YOUR_IP/~YOUR_USER/PATH/Make_XML.php
or
*/20 * * * * wget http://mysite.co.uk/PP/Make_XML.php
First make sure the url works , just by opening it with a browser
Hope it helps!
Crontab doesn't know anything about PATH variable. So use absolute path to your php (/usr/bin/php for e.g.)/ You can run command which php to find your php path

Categories