• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question Is there any way to set up a scheduled task for Magento like this in the Plesk interface?

zigojacko

Basic Pleskian
Server operating system version
CentOS 7.9
Plesk version and microupdate number
18.0.45
We absolutely have to run cron jobs for Magento as the system user that owns all the Magento files and folders and Plesk makes this very difficult.

I've resorted to actually trying to run a crontab as the user by adding and allowing it to run cron jobs (albeit if I log in as this user to SSH (which I also had to manually allow), it states 'crontab: command not recognised').

The cron job looks like the below in the crontab:-

---
* * * * * /opt/plesk/php/7.4/bin/php /var/www/vhosts/domain.tld/httpdocs/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/vhosts/domain.tld/httpdocs/var/log/magento.cron.log
---
(domain.tld is replacing the actual domain name)

I gave up trying to set this cron job up in the Plesk interface as no matter what I tried, I couldn't figure it out. It needs to run the command and then write to a log file as per the above (can this be set as an argument)? I could not find any useful documentation on how to do this online in Plesk.

P.S - it's seems a bit stupid that we don't have the ability to create additional SSH users with sudo access in Plesk.
 
Ah, yes, you're right. It's a cronjob command that is a bit tricky to get working form the Plesk UI because it's a command that should be executed from Shell. However as the crontab domains system user doesn't have Shell privileges it won't be able to (fully) execute the command. So you'll have to grand the domains system user Shell access. Which you can do on with the "Access to the server over SSH" option on the "Web Hosting Access" page from the Hosting & DNS tab from your domain in Plesk. Choose any Shell you like for the list, example /bin/sh. (Incidentally, this should also solve your issue from this post).

After that there are two ways I found to get this to work.

1) Create a Shell script (preferably outside your document root) and add the command /opt/plesk/php/7.4/bin/php /var/www/vhosts/domain.tld/httpdocs/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/vhosts/domain.tld/httpdocs/var/log/magento.cron.log there. Then call the Shell script with a crontab.

2) Alternatively add crontab via via SSH running crontab -e -u your-systemuser and start cronrab file with SHELL="/bin/sh" like:
Code:
SHELL="/bin/sh"
* * * * * /opt/plesk/php/7.4/bin/php /var/www/vhosts/domain.tld/httpdocs/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/vhosts/domain.tld/httpdocs/var/log/magento.cron.log

On a completely different note, I am not sure what the -v flag does on the grep command in your example. For me the -v flag doesn't exisit on grep.
 
Thanks for your help @Kaspar - yes, my other post you linked to was as a result of not being able to create the crontab under the system user as needed in this post.

I have already granted the system user shell privileges and I had already tried to crontab to the system user from root exactly as you said and manually added the crontab entry and this was working but when I came to check it this morning, Plesk had modified it on it's own and I tried to run it from within the Plesk interface and it had broken with the exact same problem as I originally reported.

It's a bit of a daft system if it can't handle the cron job that we are expected to run for a Magento website...

The command including the -v is taken from the Magento documentation here.
 
On a completely different note, I am not sure what the -v flag does on the grep command in your example. For me the -v flag doesn't exisit on grep.
-v, --invert-match select non-matching lines

so the grep suppresses all lines that match, as to not clutter the log.
 
Hi,
I have a question in the same direction:
I have launched cron task in scheduling task with plesk. They have been 3 hrs since I have launched the commands but till now the command can't finish as you can see in the screen attached. Any idea why this happening?
 

Attachments

  • Screenshot_20230925_172932_Chrome.jpg
    Screenshot_20230925_172932_Chrome.jpg
    88.4 KB · Views: 8
Back
Top