I have four PHP scripts that perform various tasks that need to be performed sequentially.
Instead of creating a cron entry for each PHP script, I thought I would be smart and wrap it like a Bash script, as shown below:
#!/bin/bash
NOTIFYEMAIL="webmaster@example.com"
PHP="$(which php)"
FOLDER="/var/www/example.com/processors/"
SCRIPTS=("script_1" "script_2" "script_3" "script_4")
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
I tested all the scripts separately, and they work without errors, displaying information about the processing on the terminal.
/usr/bin/php /var/www/example.com/processors/script_1.php
I even checked the Bash script, which sequentially calls four PHP scripts, manually through the terminal and also works without errors.
/bin/bash /var/www/example.com/processors/run.sh
But for some reason, PHP scripts are not executed when I leave cron to run them using the following in the root of crontab.
# process daily.
0 1 * * * /bin/bash /var/www/example.com/processors/run.sh > /dev/null
, crontab Bash script , script .
:
-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
, cron, /var/log/cron.log, grep CRON /var/log/syslog :
Mar 11 06:39:01 s00000000 CRON[11651]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Mar 11 07:09:01 s00000000 CRON[12771]: (root) CMD ( [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2>/dev/null \; -delete)
Mar 11 07:17:01 s00000000 CRON[13074]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
, , .