Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过shell将crontab中的参数传递给php脚本_Php_Shell_Cron_Crontab_Cron Task - Fatal编程技术网

通过shell将crontab中的参数传递给php脚本

通过shell将crontab中的参数传递给php脚本,php,shell,cron,crontab,cron-task,Php,Shell,Cron,Crontab,Cron Task,从我的shell脚本test.sh中,我想将一些参数传递给PHP脚本,该脚本的读取方式如下: test.sh php -q /home/user/files/test.php "$1" "$2" php -q /home/user/files/test.php $1 $2 为了测试参数的传递,我只是这样读(test.php): 我的php脚本可以很好地读取这两个参数(两次): 但如果我通过crontab运行它,它无法读取参数,我只能得到: Arg 1: Arg 2: Arg 1: Arg

从我的shell脚本test.sh中,我想将一些参数传递给PHP脚本,该脚本的读取方式如下:

test.sh

php -q /home/user/files/test.php "$1" "$2"
php -q /home/user/files/test.php $1 $2
为了测试参数的传递,我只是这样读(test.php):

我的php脚本可以很好地读取这两个参数(两次):

但如果我通过crontab运行它,它无法读取参数,我只能得到:

Arg 1: 
Arg 2: 
Arg 1: 
Arg 2: 
Cron作业如下所示:

20  13  *   *   *   /home/user/files/test.sh one two

如何通过cron作业将参数正确地传递给shell脚本,然后再传递给php?

您的php.ini中可能没有启用
register\u argc\u argv

使用php的
getopt
获取命令行参数

Arg 1: one
Arg 2: two
Arg 1: one
Arg 2: two
Arg 1: 
Arg 2: 
Arg 1: 
Arg 2: 
20  13  *   *   *   /home/user/files/test.sh one two