PHP 参数选项错误未找到 r

标签 php cron centos command-line-interface

我有一个脚本,用于运行 WP All Import Pro 的 cron 作业。该脚本在 Debian Jessie 上运行没有错误,我正在迁移到运行 CENTOS 6.7 x86_64、WHM 11.50.0 和 cPanel 的专用服务器。

在新服务器上运行脚本会引发此错误并填充自定义日志文件:

Error in argument 2, char 2: option not found r

-r 选项用于运行没有脚本标签的 php:

-r <code>        Run PHP <code> without using script tags <?..?>

目前不知道该怎么做,任何帮助将不胜感激。


PHP CLI 版本

root@host [~]# php-cli -v
PHP 5.5.28 (cli) (built: Aug 28 2015 14:51:30) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with the ionCube PHP Loader v4.7.5, Copyright (c) 2002-2014, by ionCube Ltd., and
    with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
    with Suhosin v0.9.36, Copyright (c) 2007-2014, by SektionEins GmbH

脚本

#!/bin/bash
#!/usr/bin/php-cli

## http://devlog.rolandow.com/2014/11/wp-import-cron-cli-update/

while getopts ":j:" opt; do
  case $opt in
    j)
      jobId=$OPTARG
      ;;
    \?)
      echo "Invalid option: -$OPTARG" >&2
      ;;
   :)
      echo "Option -$OPTARG requires an argument." >&2
      exit 1
      ;;
  esac
done

if [ "$jobId" = "" ]; then
  echo No job id
  exit 1
fi

# Set magic variables for current FILE & DIR
__FILE__="$(test -L "$0" && readlink "$0" || echo "$0")"
__DIR__="$(cd "$(dirname "${__FILE__}")"; echo $(pwd);)"
LOGFILE="${__DIR__}/tmp/wpai_cron_${jobId}.log"
CURLOG="${__DIR__}/tmp/wpai_cron_${jobId}_current.log"
DONE=0

function log {
  echo "$(date): $*" >>$LOGFILE
}


log "Start import for jobID $jobId"

cd $__DIR__/public_html
php -e -r 'parse_str("import_key=ica&import_id='$jobId'&action=trigger", $_GET); include "wp-cron.php";' >>$LOGFILE 2>&1
sleep 1

while [ $DONE -eq 0 ]
do
  php -e -r 'parse_str("import_key=ica&import_id='$jobId'&action=processing", $_GET); include "wp-cron.php";' >$CURLOG 2>&1
  cat $CURLOG >>$LOGFILE
  DONE=$(grep 'is not triggered' $CURLOG | wc -l)
  sleep 1
done
rm $CURLOG

log "End of import for jobId $jobId"
log ""
log ""

错误

Fri Sep  4 05:17:41 EDT 2015: Start import for jobID 04
Error in argument 2, char 2: option not found r
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
       php <file> [args...]
  -a               Run interactively
  -b <address:port>|<port> Bind Path for external FASTCGI Server mode
  -C               Do not chdir to the script's directory
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse <file>.  Implies `-q'
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -q               Quiet-mode.  Suppress HTTP Header output.
  -s               Display colour syntax highlighted source.
  -v               Version number
  -w               Display source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.
  -T <count>       Measure execution time of script repeated <count> times.

最佳答案

我有与你完全相同的脚本和设置,只是改变

php -e -r

php5-cli -e -r

让它顺利运行。请注意,它位于脚本中的 2 个位置。

关于PHP 参数选项错误未找到 r,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32401398/

相关文章:

php - SQL 查询未给出预期结果

php - 通过链接获取网站标题

php - 如何在 Laravel 中解密哈希密码

bash - 音频无法在 Raspberry Pi 上使用 crontab 播放

为 XMLReader 安装 php-xml 时,php54 与 php53 常见冲突

java - 在没有提示的情况下在 Linux/CentOS 上安装和升级 Java

php - XML 到 Mysql 中的一个元素位于错误的行中

python - cron 作业没有将输出写入正确的输出日志文件

linux - Crontab 不启动脚本

laravel - C-Panel/VM/Laravel 错误 - 打开 "https://example.com"时,它会重定向到 "allowandgo.com/?p=gm3ggojwgq5gi3bphezda"这个 URL