Note that there are some explanatory texts on larger screens.

plurals
  1. POSequence of PHP Scripts in Bash script executed by Cron not running
    text
    copied!<p>I have four PHP scripts that perform various tasks that need to be executed sequentially.</p> <p>Instead of creating a cron entry for each PHP script, I thought I would be clever and wrap it up as a Bash script as below:</p> <pre><code>#!/bin/bash # set notification email. NOTIFYEMAIL="webmaster@example.com" # set PHP path. PHP="$(which php)" # set folder path. FOLDER="/var/www/example.com/processors/" # list of scripts. SCRIPTS=("script_1" "script_2" "script_3" "script_4") # execute each script. for i in "${SCRIPTS[@]}" do SCRIPT="$FOLDER/$i.php" printf "Processing: %s\n" $i chmod +x $SCRIPT $PHP $SCRIPT done echo "Scripts have been processed." | mail -s "Scripts Processed" $NOTIFYEMAIL </code></pre> <p>I've tested all the scripts individually, and they work without error, outputting processing information to the terminal.</p> <pre><code>/usr/bin/php /var/www/example.com/processors/script_1.php </code></pre> <p>I've even tested the bash script which calls the four PHP scripts in sequence, manually via the terminal and that also works without error.</p> <pre><code>/bin/bash /var/www/example.com/processors/run.sh </code></pre> <p>But for some reason, the PHP scripts don't execute when I leave cron to run them using the following on the <strong>root</strong> users crontab.</p> <pre><code># process daily. 0 1 * * * /bin/bash /var/www/example.com/processors/run.sh &gt; /dev/null </code></pre> <p>I know that the crontab has been processed and the Bash script has run because I always receive the notification e-mail at the end of the script, each and every time.</p> <p>Permissions are as follows:</p> <pre><code>-rwxr-xr-x 1 root root 510 Mar 11 09:21 run.sh -rwxrwxr-x 1 git git 2.8K Mar 8 10:17 script_1.php -rwxrwxr-x 1 git git 2.6K Mar 1 18:07 script_2.php -rwxrwxr-x 1 git git 717 Mar 1 18:07 script_3.php -rwxrwxr-x 1 git git 6.8K Mar 4 16:30 script_4.php </code></pre> <p>There are no cron-specific log files such as <code>/var/log/cron.log</code> but when I run <code>grep CRON /var/log/syslog</code> and it returns the following generic output: </p> <pre><code>Mar 11 06:39:01 s00000000 CRON[11651]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] &amp;&amp; [ -d /var/lib/php5 ] &amp;&amp; find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2&gt;/dev/null \; -delete) Mar 11 07:09:01 s00000000 CRON[12771]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] &amp;&amp; [ -d /var/lib/php5 ] &amp;&amp; find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2&gt;/dev/null \; -delete) Mar 11 07:17:01 s00000000 CRON[13074]: (root) CMD ( cd / &amp;&amp; run-parts --report /etc/cron.hourly) </code></pre> <p>Any suggestions for things for me to try would be appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload