How to fix cron schedule issue? - centos7

I tried to run this command manually and working fine
/var/www/html/crm/cron/vtigercron.sh
but when I schedule cron with the below to run automatically nothing happens
* * * * * root /var/www/html/crm/cron/vtigercron.sh
just gives me
Redirecting to /bin/systemctl status crond.service

Related

How do you run Drush commands via crontab on Drupal 8

I am trying to execute drush commands through a crontab for a Drupal 8 site. These commands work when I call them directly, but when run through my user's crontab I get the following error:
\Drupal::$container is not initialized yet. \Drupal::setContainer() must be
called with a real container.
Other posts suggest this is a bug within older versions of Drush, but I am on 10.3.5.
I have tried a number of things over the past few hours including reconfiguring cron, but ultimately it seems Drush is not bootstrapping Drupal correctly, but I need to be able to run the queue from cron
This is a test command I'm running which just adds to the Drupal log...
crontab (my user)
* * * * * /var/www/html/vendor/bin/drush scr /var/www/html/scripts/what.php -r /var/www/html/web
what.php
<?php
\Drupal::logger('mymod')->info("CHECKING IN FROM CRON CLI...");
Here is another command, closer to what I'm trying to accomplish...
crontab (my user)
* * * * * /var/www/html/vendor/bin/drush queue:run commerce_recurring -r /var/www/html/web >> /var/www/html/private/logs/cron_commerce_recurring.log
The error I get here is:
Command queue:run was not found. Drush was unable to query the database. As
a result, many commands are unavailable. Re-run your command with --debug
to see relevant log messages.
I get this same error when running this command with drupal console.
Any suggestions appreciated.
Thanks.
This turned out to be a database connectivity issue. The tricky part was getting to the error. I had to install an MTA, so that cron could write errors to my local user's mailbox and then add the --debug option, so that I could see the real error.
I'm working on a DDEV instance and for some reason the DDEV settings were not being loaded. An issue for another day...

Cron with elastic beanstalk and symfony - not working

I'm a newbie developer and I am messing around with Symfony and AWS. I have a Symfony app deployed via elastic beanstalk and I am trying to add a cron job every minute.
Basically I want the cron job to execute a Symfony command I created : update-pings, that is supposed to update some fields in my RDS DB.
I'm using a 02-crons.config file in my ./ebextensions directory that looks like this (greatly inspired from AWS documentation https://aws.amazon.com/fr/premiumsupport/knowledge-center/cron-job-elastic-beanstalk/ ) :
files:
"/etc/cron.d/mycron":
mode: "000644"
owner: root
group: root
content: |
* * * * * root php /var/app/current/bin/console app:update-pings
commands:
remove_old_cron:
command: "rm -f /etc/cron.d/mycron.bak"
Well, first of all, this is not working, the fields in the DB are not updating. So i connected in SSH to my EC2 instance to see what's happening.
The mycron file in /etc/cron.d/was correctly created with * * * * * root php /var/app/current/bin/console app:update-pingsinside of it.
Now, I tried replacing the content of this file by a simple * * * * * root echo test >> /tmp/cron_temp, this is working perfectly, a line with 'test' is added in my cron_temp file every minute
I tried running the initial command php /var/app/current/bin/console app:update-pingsmanually on the instance, works perfectly as ec2-user
When I switch to root user using sudo su -, the command still works. But when I try to run it with sudo, it fails, not sure if that's any relevant :
In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_DBNAME".
I believe there is something I'm missing with linux users/rights, but I'm a total newbie with that and cannot find what's going on
Any ideas ? Thanks a lot in advance ! :)
Edit 1 : I'm know logging the sterr of the commande into a file and I get the same environment variable error as when I try to run the command manually with sudo
In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_DBNAME".
The command works fine without sudo though

Django background tasks not taking new code into account

I am using django background tasks to run some code in background. My project has been deployed and I run the background tasks using cron. The problem is when I made changes to my code, the ones related to the background tasks are not taken into account. It seems the cron still using the old code.
This is my crontab
*/5 * * * * /home/.../venv/bin/python /home/.../manage.py process_tasks [duration 299]
I think i need to kill the cron command and allow the code to update before running it again.

Crontab visible in logs but still doesn't seem to run?

I'm on an AWS server. I wrote a crontab and placed it on the server under /etc/cron.d. The contents of the crontab are the following:
SHELL=/bin/bash
PATH=/sbin:/bin:usr/sbin:/usr/bin
MAILTO=root
HOME=/
*/5 * * * * root <full-path-to-write-command> >> <full-path-to-txt-output-file>
After running sudo service crond restart, I check the logs by doing sudo tail -f /var/log/cron.
I can observe the cronjob in the logs:
<date-time-stamp> ip-<ip-address> CROND[12930]: (root) CMD (<full-path-to-write-command> >> <full-path-to-txt-output-file>)
However, when I check the <full-path-to-txt-output-file>, I don't see file being written to.
What could be the problem, if I see that the cronjob is executing? Thanks

Amazon Web Services - cronjob not running every minute

I have a cronjob defined on an AWS ec2 (so it uses crontab). I did crontab -e and added this line into it:
*/1 * * * * /usr/bin/php /path/to/file/file.php
I saved it with vim and it says crontab: installing new crontab. I also made the permissions on the file 755, using chmod, and I put the proper shebang (#!/usr/bin/php -q) at the top of file.php. The script should update a database every minute, but I am not seeing the database get updated at all. What did I do wrong?
logging example:
*/1 * * * * >> /var/log//your_cron.log 2>&1