skip to Main Content

I can’t execute a shell script with a cron job on WordPress (knowing that I can’t use crontab). I can execute it with ‘sh my_script.sh’, but not with a cron job.

I’ve tried various scripts like this:

// Define the function that will execute your shell script
function execute_shell_script() {
    // Path to the shell file to execute
    $script_path = 'site/public_html/wp-content/plugins/github_install.sh';

    // Execute the shell script
    shell_exec($script_path);
}

// Schedule the execution of your function at a specific frequency
add_action('update_plugin', 'execute_shell_script');
if (!wp_next_scheduled('update_plugin')) {
    wp_schedule_event(time(), 'daily', 'update_plugin');
}

I want to pull from GitHub every day if there is an update.

2

Answers


  1. Chosen as BEST ANSWER

    It is not possible to use chmod on the server. I also tried shell_exec but without success.


  2. You need to update your code to execute the shell script properly (ensure that the script file is in the correct location, and accessible from your project):

    shell_exec("sh $script_path");
    

    Make sure that your script itself has the executable permission

    chmod +x script.sh
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search