开发者

how to send multiple commands to a file in cron?

I have a file that is having some multiple dynamic parameters.I want to send these parameters at the tim开发者_Python百科e of writing a file in main cron file. Something like this ->

*/15 * * * * /usr/bin/php /a/b/c.php parameter1 parameter2 parameter3 parameter4

Now i tried working this up but my file is not executing. What im concerned about is that how will my php file will fetch these parameters ?? And how will i write this command when there is only 2 parameters to be passes parameter1 and parameter4??? and how will my cron and php will recognoze that which parameter is for which data and all?? please advice!!


*/15 * * * * "/usr/bin/php /a/b/c.php parameter1 parameter2 parameter3 parameter4"

maybe...

also you can pass it as a query string? p1=123&p2=432&p3=456 within the script you can just do a parse_string to convert it into an array...


In this case it will be $argv array in your script with those parameters.

Also you can make an executable file with contents:

#!/usr/bin/php
<?
    require('yourscript.php');

And make it executable with chmod +x thisfile. Just not to pass your file name to php interpreter in crontab.


The way you need to go about making this script work is the following:

In the cron script set the parameters to each be query strings. For example, set p1=1234 as parameter1, etc.

Within the PHP script, you will need to reference the $argv array to get the parameters passed in.

$argv[1] will be parameter1, $argv[2] is parameter2, and so forth.

You can identify which parameter is which by using the explode command to separate the key from the value:

for($x=1; $x < $argc; $x++) {
    list($key, $value) = explode('=', $argv[1]);
    $paramarray[$key] = $value;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜