• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Resolved Frustrated because of cronjob

Fabhino22Elz

Basic Pleskian
Server operating system version
Plesk Obsidian Version - CentOS Linux 7.9.2009 (Core)
Plesk version and microupdate number
18.0.57
Hey,
I am running a server, where I created a PHP script with some commands to import in stock data for my store. If I run the file directly via console, it works all fine.

If I put it in the planned tasks section it is not working anymore as not all commands are run... (I guess, because of the path from where it is started?

So I created a .sh file directly beside the .php. If I do so in terminal - again, everything works. If I now add the file to the scheduled task, it is also not working as not all commands are run...

I guess you all see the time... I am highly frustrated, as this is the last small step to automate my stock managing. Hope someone here can help me.

Greetings
 
As you already guessed, the symptom is likely caused by missing or wrong paths. You only need to make sure that no relative paths are used, but instead fully qualified paths are used. This needs to be checked and fixed inside the script that is trying to run or open other files.
 
As you already guessed, the symptom is likely caused by missing or wrong paths. You only need to make sure that no relative paths are used, but instead fully qualified paths are used. This needs to be checked and fixed inside the script that is trying to run or open other files.
Hello Peter,
thank you first for your reply.

With fully qualified path you mean starting from the directory of the vhost where I add the scheduled task or the pwd path?

And does this count only for the link to the PHP file or also for the command (php) that I want to run?

This is how it looks currently, because the .sh file is directly beside the PHP file.


Code:
#!/bin/bash

# Pfad zur PHP-Interpretation
php_path="/usr/bin/php"

# Pfad zur PHP-Datei
php_file="filename.php"

# PHP-Datei ausführen
$php_path $php_file
 
Hey again. I tried to use the full path (var/www/…) and stepping into the same issue again. The script shows, that it is running, but it is performed in the main directory of the vhost. What not should be the case. The PHP file is in a specific folder. If I connect via terminal to this folder and run the .sh script from there it works fine.

But as soon as I run it via the scheduled task the issue happens again that it is performed from the vhost root…
 
You'll need
php_file="/var/www/vhosts/<your subscription domain>/<your document root>/path/path/filename.php"

Also, /usr/bin/php is a bad idea to use, because it is not accessible from the chrooted environment. Instead, use "Run PHP script" in the scheduled task configuration. If that is not feasible, you can call PHP, but then need to
a) set the SSH shell to an ordinary shell with full access to the server (not recommended)
b) start PHP with /opt/plesk/php/<version>/bin/php
 
You'll need
php_file="/var/www/vhosts/<your subscription domain>/<your document root>/path/path/filename.php"

Also, /usr/bin/php is a bad idea to use, because it is not accessible from the chrooted environment. Instead, use "Run PHP script" in the scheduled task configuration. If that is not feasible, you can call PHP, but then need to
a) set the SSH shell to an ordinary shell with full access to the server (not recommended)
b) start PHP with /opt/plesk/php/<version>/bin/php
Thank you, I was finally able to resolve this issue.

Have a great start into 2024!
 
You'll need
php_file="/var/www/vhosts/<your subscription domain>/<your document root>/path/path/filename.php"
Also, /usr/bin/php is a bad idea to use, because it is not accessible from the chrooted environment.
Waaait. If you're in a chrooted environment, shouldn't /var/www/vhost/<domain> be the chroot jail and thus removed from the file path?
 
Back
Top