• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • 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.

Issue NO way to add $PATH on crontab

2dareis2do

Basic Pleskian
Server operating system version
CentOS
Plesk version and microupdate number
18.0.62 Update #2
When running crontab as user, it is sometimes useful to be able to set or override the path

Here is an example

MAILTO="[email protected]"
SHELL="/bin/sh"
PATH=/usr/local/bin:$PATH
45 * * * * /opt/plesk/php/8.3/bin/php -f '/var/www/vhosts/mydomain/httpdocs/vendor/bin/drush' -- 'core:cron'

In this example I need to add the usr/local/bin to $PATH so that it can run the correct python version that is installed in /usr/local/bin

From admin Ui there is no way to set path unless editing with crontab -e

See How to get CRON to call in the correct PATHs for more info

Screenshot

Screenshot 2024-08-12 at 20.54.15.png
 
OK I followed your advice and set up another script. This seemed to get me around the PATH issue as I could override the path there,

However there seemed to run into another issue when running php from the script.

What does work is changing the shell from under web hosting and set to ;/usr/bin/bash

I am not accessing from the control panel but otherwise shell access seems to be set to forbidden by default.

This means that when switching to user in shell, bash shell is assigned automatically and path includes /usr/local/bin as per mai root user shell

Now I have the option now of using either another script, or just running directly from cron.

Seems to be working now.

Mayybe there is a better way?

Thanks for your help.
 
Actually I did end up using a bash script. Still problem with working from cron eve with default shell changed,

e.g.

Code:
#!/bin/sh
#
# DRUSH WRAPPER
#
# A wrapper script which launches the Drush that is in your project's /vendor
# directory.  Copy it to the root of your project and edit as desired.
# You may rename this script to 'drush', if doing so does not cause a conflict
# (e.g. with a folder __ROOT__/drush).
#
# Below are options which you might want to add. More info at
# `drush topic core-global-options`:
#
# --local       Only discover commandfiles/site aliases/config that are
#               inside your project dir.
# --alias-path  A list of directories where Drush will search for site
#               alias files.
# --config      A list of paths to config files
# --include     A list of directories to search for commandfiles.
#
# Note that it is recommended to use --local when using a drush
# wrapper script.
#
# See the 'drush' script in the Drush installation root (../drush) for
# an explanation of the different 'drush' scripts.
#
# IMPORTANT:  Modify the path below if your 'vendor' directory has been
# relocated to another location in your composer.json file.
# `../vendor/bin/drush.launcher --local $@` is a common variant for
# composer-managed Drupal sites.
#
export PATH=/usr/local/bin:./vendor/bin/$PATH
/opt/plesk/php/8.3/bin/php -f 'httpdocs/vendor/bin/drush' -- $@
 
Back
Top