通过shell将crontab中的参数传递给php脚本
从我的shell脚本test.sh中,我想将一些参数传递给PHP脚本,该脚本的读取方式如下: test.sh通过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
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