0

Sorry if this has already been answered, but I have looked around and have been unable to find the help, I've followed countless tutorials etc, just can't get my head around it.

So I have a Magento 2.1.0 website running, but It needs the standard Magento cron jobs that do the The following tasks.

Catalog Price rules Sending Newsletters Generating Google Sitemaps Customer Alerts/Notifications (product price change, product back to stock) Automatic updating of currency rates Scheduled DB logs cleanup

However, when I try via SSH I get permission error when entering this command, so am unable to progress further, despite using the system username that has the valid permissions:

*crontab -u magento_user -e*

So I have tried doing it via plesk, but I get a "No such file exists error" when using this command (using my details obviously):

* * * * * <path to php binary> <magento install dir>/bin/magento cron:run | grep -v "Ran jobs by schedule" >> <magento install dir>/var/log/magento.cron.log

Apparently Magento.cron.log doesn't exist.

I'm stuck right now, and just really need to get this sorted. I have looked through the files through ftp, and I can't find the cron.php file everywhere seems to be referring too, so i'm completely baffled right now. Does anyone know what I am doing wrong, or what I can do to find out what the issue is.

Thank you for any help in advance.

Kind regards

0

I don't know what you are doing wrong but I can tell you how I set up Magento2 cron on a recent project.

I have been putting files inside the /etc/cron.d/ folder. This may be specific to certain Linux distributions and may be specific to how a particular Linux box is set up.

But in theory any file inside the /etc/cron.d/ folder will be run by cron. The syntax is slightly different but this method avoids having to work out which users' crontab to edit.

So:

# File : /etc/cron.d/magento2
# Run Magento2 cron every 7 minutes 
*/7 * * * * magento_user php /var/www/html/magento2/bin/magento cron:run

[Linux commands* to create the file are cd /etc/cron.d/ ls -l vim magento2 ]

  • ls -l will show you the files here already.

  • *you might prefer to type nano magento2 instead of vim magento2, nano being a slightly more user-friendly editor for those unaccustomed to editing text files in Linux

  • please note: add a blank line at the end of this text file after the cron entry so the file ends with an empty line (this may be superstition but there is no harm in it)

To check that cron is running, on the Linux command prompt enter:

grep CRON /var/log/syslog

if that fails (Linux setups vary in where cron logs to) try

tail -n 100 /var/log/cron

[if that fails, hit the internet for advice such as this from Benjamin Cane]

You should see some log entries from various cron jobs that are running. If you do not see any recent entries then perhaps the Linux cron is not running but I think that would be unusual (and a whole different Q&A).

Eventually you should see a Magento entry in your Linux cron log due to the file you put in /etc/cron.d/ for example I see this:

CROND[3196]: (magento_user) CMD (php /var/www/html/magento2/bin/magento cron:run)

Then the main way I check Magento cron is behaving is to study the Magento database table cron_schedule closely (using a tool such as MySQL Workbench).

If the Linux OS cron is calling Magento2 cron then you should see entries in this table with status pending. Presently you should see status complete or perhaps a useful error message to indicate where the Magento cron failed.

==================================

Adendum

I re-read your question.

  • cron.php is from Magento 1.x so you should ignore any advice related to that
  • if you want to log to <magento install path>/var/log/some-cron-file.log then you do probably need to create that file first by cd /full-path-to-magento-install/var/log/, ls -l, touch some-cron-file.log and then the harder part: give your new file the correct ownership and permissions for Linux cron to be able to write here. I don't know what they are for you but I know you can work that out. (but you don't really need to make your own log entries, the Linux system will most likely, and can be set to, log cron jobs to syslog or a dedicated log file)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.