Cronjob does not work anymore

PaulMD

Verified User
Joined
Sep 18, 2016
Messages
16
I did a ImageMagick install on my CentOS webserver and afterwards my cronjobs do not work anymore. And I do not know what is causing it.

I have cronjobs that executes php files. For example one cronjob execute every 15 minutes a php file that reads a json file and insert variables in my mysql database. I did not change the php files and they still work from the command line with php -q /home/admin/domains/domain.nl/public_html/command/myfile.php
The status of my cron is:
[admin@server domains]$ service crond status
Redirecting to /bin/systemctl status crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-07-10 22:52:30 CEST; 10h ago
Main PID: 13519 (crond)
CGroup: /system.slice/crond.service
└─13519 /usr/sbin/crond -n[/code]
I have tried to restart my server, I have restart my cron service without result.
My /var/log/cron looks like
Jul 11 09:13:01 server CROND[11480]: (root) CMD (/usr/local/directadmin/dataskq)
Jul 11 09:14:01 server CROND[11629]: (root) CMD (/usr/local/directadmin/dataskq)
Jul 11 09:15:01 server CROND[11792]: (root) CMD (/usr/local/directadmin/dataskq)
Jul 11 09:15:01 server CROND[11791]: (admin) CMD (php -q /home/admin/domains/domain.nl/public_html/command/myfile.php)
Jul 11 09:16:01 server CROND[11931]: (root) CMD (/usr/local/directadmin/dataskq)
Jul 11 09:17:01 server CROND[12075]: (root) CMD (/usr/local/directadmin/dataskq)
Jul 11 09:18:01 server CROND[12244]: (root) CMD (/usr/local/directadmin/dataskq)
Jul 11 09:19:01 server CROND[12375]: (root) CMD (/usr/local/directadmin/dataskq)
Jul 11 09:19:43 server crontab[13932]: (root) LIST (admin)
Jul 11 09:20:01 server CROND[13993]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 11 09:20:01 server CROND[13994]: (root) CMD (/usr/local/directadmin/dataskq)
Jul 11 09:21:01 server CROND[14168]: (root) CMD (/usr/local/directadmin/dataskq)
With
php -q /home/admin/domains/domain.nl/public_html/command/myfile.php 2>&1 >>php -q /home/admin/domains/domain.nl/public_html/command/errorlog.txt
I try to view an extra error log, but the output to errorlog.txt is empty (but the file is written!).

So I do not understand why the cronjob/php-file is doing nothing? What steps can I do to find the problem with the cronjob/php?

Because the command-line works, and I did not change the cronjob or the php file I suspect it has to do something with the installation of ImageMagick. But I do not know what. During installation I got some errors and I used the command: mount -o remount,exec /tmp to get it working.
 
Obviously crond is working so that is not the problem. The errorlog.txt is being created so the script is running. If its not doing what its supposed to be doing then there is something wrong with the script.

Are you manually running the script from command line as root or as admin?
 
I can run the script manually from command line as admin and as root without a problem.
 
Also cron does not inherit environment variables. I don't what is in the script but many times full paths are required to files and executables.
 
The php script worked for weeks with cronjob. Now it still works from command line and from website. The php script itself can not have a problem, i did not change it. The script gets an json file and insert it into mysql. No paths are used only a file that will be downloaded from outside with https://www...
 
I found a direct relation with imagick. But I do not know what to do.

I run a new cron with
1 * * * * /path/to/your/cron.php &>/tmp/mycommand.log
1 * * * * /path/to/your/cron.php >/tmp/mycommand.log 2>&1
and the php file was an echo with Hello.

And in the mycommand.log I see:
Code:
PHP Warning:  Module 'imagick' already loaded in Unknown on line 0
<?

echo "Hello";

?>


Quickfix: changing php -q in my crontab to /usr/local/bin/php
For the problem with two loaded imagick I load the imagick from php.ini and imagick.ini. I removed it from the php.ini. But still have "PHP Warning: Module 'imagick' already loaded in Unknown on line 0" after a reboot.
 
Last edited:
It shouldn't stop script execution but that warning is telling you are trying to load the same module more than once, check your php.ini.
On the other hand you seem to be using a wrong PHP open tag.
It should be
PHP:
<?php
Unless you specifically enabled short open tag.
 
Back
Top