Pass a value to a script in cron
I'm running a script in cron, and would like to pass a value to the script.
I'm trying to do something like this in crontab:
-
开发者_JS百科
- php -q /home/cron/some_script.php?variable=1
Where the variable would be read by $_GET in the script.
I can't seem to find an answer anywhere, thanks for your help!
You probably want to use argv:
/path/to/script.php x y z
Then, in script.php:
print_r($argv);
Which gives you:
Array
(
[0] => ./script.php
[1] => x
[2] => y
[3] => z
)
You seem to be confusing a webserver and a shell.
/home/cron/some_script.php
Is your script. If you want to pass things into it on the command line you would do:
/home/cron/some_script.php arg1 arg2
And parse the arguments in your script.
精彩评论