diff --git a/roundcube-cleandb.sh b/roundcube-cleandb.sh index 394824b..3c52a94 100755 --- a/roundcube-cleandb.sh +++ b/roundcube-cleandb.sh @@ -252,6 +252,21 @@ if [[ ! -x "$CLEANDB_SCRIPT" ]] ; then fatal "Script '${CLEANDB_SCRIPT}' is not executable!" fi +# - 'cleandb.sh' starts with '#!/usr/bin/env php', so php must be found in +# the PATH of the executing user. Under cron the PATH usually lacks the +# php binary directory (e.g. /usr/local/php/bin) and contains directories +# like /root/bin, which are not accessible for $HTTP_USER ('env: php: +# Permission denied'). So determine php here and pass a clean PATH. +# - +PHP_BIN="$(command -v php 2> /dev/null)" +if [[ -z "$PHP_BIN" ]] && [[ -x "/usr/local/php/bin/php" ]] ; then + PHP_BIN="/usr/local/php/bin/php" +fi +if [[ -z "$PHP_BIN" ]] ; then + fatal "No php binary found (neither in PATH nor '/usr/local/php/bin/php')!" +fi +RUN_PATH="$(dirname "$PHP_BIN"):/usr/local/bin:/usr/bin:/bin" + if $terminal ; then echo "" @@ -264,6 +279,7 @@ if $terminal ; then echo -e " Install directory (via htdocs).......: $INSTALL_DIR" echo -e " Script to be run......................: $CLEANDB_SCRIPT" echo -e " Executing user........................: $HTTP_USER" + echo -e " PHP binary............................: $PHP_BIN" echo "" fi @@ -278,7 +294,8 @@ if $terminal ; then fi echononl " Running 'cleandb.sh' for '${HOSTNAME_WEBMAIL}'.." -su -c "$CLEANDB_SCRIPT" -s /bin/bash $HTTP_USER > $log_file 2>&1 +su -c "cd /tmp && export PATH=$(printf '%q' "$RUN_PATH") && $(printf '%q' "$CLEANDB_SCRIPT")" \ + -s /bin/bash $HTTP_USER > $log_file 2>&1 RC=$? if [[ $RC -eq 0 ]]; then