Author Topic: Cron job works from command line but not in cron  (Read 8175 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Cron job works from command line but not in cron
« on: July 22, 2019, 04:11:45 PM »
Hello,

The following works for me from the command line:

/usr/local/bin/php /home/tetra/help/public_html/api/cron.php

However, I've tried the following cron jobs and none of them have produced any results:

* * * * * tetra /usr/local/bin/php /home/tetra/help/public_html/api/cron.php
* * * * * nobody /usr/local/bin/php /home/tetra/help/public_html/api/cron.php
* * * * * /usr/local/bin/php /home/tetra/help/public_html/api/cron.php
* * * * * /opt/alt/php-fpm70/usr/bin/php /home/tetra/help/public_html/api/cron.php

The permissions for that file are 755. I've checked my cron logs, and I'm not 100% sure it is being run at all, but honestly I do not know how to identify for sure. This is for the past hour and I've had 1 minute crons in this queue for over an hour and this is the only output from tail (I wasn't able to do this as the user, I had to do it as root):

Code: [Select]
Jul 22 14:10:01 server3 CROND[24716]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 14:20:01 server3 CROND[25605]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 14:30:01 server3 CROND[28042]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 14:40:01 server3 CROND[21551]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 14:50:01 server3 CROND[7167]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:00:01 server3 CROND[4888]: (root) CMD (/usr/share/clamav/freshclam-sleep)
Jul 22 15:00:01 server3 CROND[4889]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:01:01 server3 CROND[4969]: (root) CMD (run-parts /etc/cron.hourly)
Jul 22 15:01:01 server3 run-parts(/etc/cron.hourly)[4969]: starting 0anacron
Jul 22 15:01:01 server3 run-parts(/etc/cron.hourly)[4978]: finished 0anacron
Jul 22 15:10:01 server3 CROND[6247]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:20:01 server3 CROND[6985]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:30:01 server3 CROND[7756]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:40:01 server3 CROND[10443]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:50:02 server3 CROND[14263]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 16:00:01 server3 CROND[15617]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 16:01:01 server3 CROND[15689]: (root) CMD (run-parts /etc/cron.hourly)
Jul 22 16:01:01 server3 run-parts(/etc/cron.hourly)[15689]: starting 0anacron
Jul 22 16:01:01 server3 run-parts(/etc/cron.hourly)[15698]: finished 0anacron
Jul 22 16:10:01 server3 CROND[16183]: (root) CMD (/usr/lib64/sa/sa1 1 1)

Offline
*
Re: Cron job works from command line but not in cron
« Reply #1 on: January 12, 2020, 05:20:48 PM »
I have a similar problem, but my var/log/cron has different output

Code: [Select]
Jan 12 14:00:01 forseti CROND[23025]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:00:52 forseti crond[77]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 68% if used.)
Jan 12 14:00:52 forseti crond[77]: (CRON) INFO (running with inotify support)
Jan 12 14:01:01 forseti CROND[992]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:01:01 forseti CROND[993]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:02:01 forseti CROND[1091]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:02:01 forseti CROND[1092]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:03:01 forseti CROND[1431]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:03:01 forseti CROND[1430]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:04:02 forseti CROND[1540]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:04:02 forseti CROND[1541]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:05:01 forseti CROND[1640]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:05:01 forseti CROND[1639]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:06:01 forseti CROND[1751]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:06:01 forseti CROND[1750]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:07:01 forseti CROND[1857]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable
Jan 12 14:07:01 forseti CROND[1856]: (CRON) CAN'T FORK (child_process): Resource temporarily unavailable

If I run the scripts from shell work perfectly (is not a problem with the script itself) but cron can't run. Checking more carefully only the root crons are running  :-\

Re: Cron job works from command line but not in cron
« Reply #2 on: January 12, 2020, 06:51:51 PM »
One minute crons!  ::)
Ask your trained sysadmin to help.
« Last Edit: January 12, 2020, 06:54:28 PM by ejsolutions »

Offline
*
Re: Cron job works from command line but not in cron
« Reply #3 on: January 12, 2020, 08:17:43 PM »
One minute crons!  ::)
Ask your trained sysadmin to help.

What is the relation about 1-minute crons and cron does not work? I believe that you are a trained sysadmin that does not have any problem to share acknowledgment, right?  ;)

Re: Cron job works from command line but not in cron
« Reply #4 on: January 13, 2020, 01:45:44 AM »
Cron is available to run periodic jobs; cron daemon reads the contents of crontabs every minute and passes appropriate commands to the task queue. The intention is not to run jobs at one minute intervals: you run scripts/processes to do that. Anacron is a variation of cron.

Syntax error:
Code: [Select]
* * * * * tetra /usr/local/bin/php /home/tetra/help/public_html/api/cron.php
* * * * * nobody /usr/local/bin/php /home/tetra/help/public_html/api/cron.php

Code: [Select]
crontab -u tetra -e
Code: [Select]
*/5 * * * * /usr/local/bin/php -f /home/tetra/help/public_html/api/cron.php(5min interval & -f may be optional with CentOS)

Quote
755
- appropriate for directories, not files - try 600 or 644 (less secure)

This is basic *nix stuff.
(UNIX System V R4.2 NCR trained circa 1992 - numerous *nix flavours since.)

Offline
*
Re: Cron job works from command line but not in cron
« Reply #5 on: January 13, 2020, 01:58:17 AM »
Hello,

The following works for me from the command line:

/usr/local/bin/php /home/tetra/help/public_html/api/cron.php

However, I've tried the following cron jobs and none of them have produced any results:

* * * * * tetra /usr/local/bin/php /home/tetra/help/public_html/api/cron.php
* * * * * nobody /usr/local/bin/php /home/tetra/help/public_html/api/cron.php
* * * * * /usr/local/bin/php /home/tetra/help/public_html/api/cron.php
* * * * * /opt/alt/php-fpm70/usr/bin/php /home/tetra/help/public_html/api/cron.php

The permissions for that file are 755. I've checked my cron logs, and I'm not 100% sure it is being run at all, but honestly I do not know how to identify for sure. This is for the past hour and I've had 1 minute crons in this queue for over an hour and this is the only output from tail (I wasn't able to do this as the user, I had to do it as root):

Code: [Select]
Jul 22 14:10:01 server3 CROND[24716]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 14:20:01 server3 CROND[25605]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 14:30:01 server3 CROND[28042]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 14:40:01 server3 CROND[21551]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 14:50:01 server3 CROND[7167]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:00:01 server3 CROND[4888]: (root) CMD (/usr/share/clamav/freshclam-sleep)
Jul 22 15:00:01 server3 CROND[4889]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:01:01 server3 CROND[4969]: (root) CMD (run-parts /etc/cron.hourly)
Jul 22 15:01:01 server3 run-parts(/etc/cron.hourly)[4969]: starting 0anacron
Jul 22 15:01:01 server3 run-parts(/etc/cron.hourly)[4978]: finished 0anacron
Jul 22 15:10:01 server3 CROND[6247]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:20:01 server3 CROND[6985]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:30:01 server3 CROND[7756]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:40:01 server3 CROND[10443]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 15:50:02 server3 CROND[14263]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 16:00:01 server3 CROND[15617]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 22 16:01:01 server3 CROND[15689]: (root) CMD (run-parts /etc/cron.hourly)
Jul 22 16:01:01 server3 run-parts(/etc/cron.hourly)[15689]: starting 0anacron
Jul 22 16:01:01 server3 run-parts(/etc/cron.hourly)[15698]: finished 0anacron
Jul 22 16:10:01 server3 CROND[16183]: (root) CMD (/usr/lib64/sa/sa1 1 1)

@bentsea I made several tests and figure out that accounts that I have migrated from cPanel (using the restore cP account available on CWP GUI) for some reason cron not work at all. if I create an account in CWP cron works perfectly.

Maybe this looks stupid but works for me  ???

is the cron issue occurring on a migrated cpanel account?

Offline
*
Re: Cron job works from command line but not in cron
« Reply #6 on: January 13, 2020, 02:02:29 AM »
Cron is available to run periodic jobs; cron daemon reads the contents of crontabs every minute and passes appropriate commands to the task queue. The intention is not to run jobs at one minute intervals: you run scripts/processes to do that. Anacron is a variation of cron.

Syntax error:
Code: [Select]
* * * * * tetra /usr/local/bin/php /home/tetra/help/public_html/api/cron.php
* * * * * nobody /usr/local/bin/php /home/tetra/help/public_html/api/cron.php

Code: [Select]
crontab -u tetra -e
Code: [Select]
*/5 * * * * /usr/local/bin/php -f /home/tetra/help/public_html/api/cron.php(5min interval & -f may be optional with CentOS)

Quote
755
- appropriate for directories, not files - try 600 or 644 (less secure)

This is basic *nix stuff.
(UNIX System V R4.2 NCR trained circa 1992 - numerous *nix flavours since.)

Thanks ejsolutions for the great explanation!  :)

Offline
*
Re: Cron job works from command line but not in cron
« Reply #7 on: January 13, 2020, 03:02:18 AM »
Finally I resolved my issue recreating the accounts, cron works fine before that.