2012-11-14 92 views
1

我有它运行在cron每天一个bash脚本在上午1:01在bash脚本是:固定 - bash脚本通过数组循环和运行PHP脚本与ARG

array_of_clients=(2 187 317 927 1863 2993 3077 3440 3444 3457 3459 3469 3484 3487 3494 3497 3522 3544 3551 3553) 

for i in "${array_of_clients[@]}" 
do 
    echo "\nRunning Client - $i" 
    php -f "/mnt/www/bin/scheduled/import_client.php" $i 
    echo "\nFinished Client - $i" 
done 

这个问题是我不不知道$ i是否被作为参数传递给php脚本。难道我做错了什么 ?如果我把$ i放在“”里面,它说找不到该文件,因为文件名变成了/mnt/www/bin/scheduled/import_client.php 2例如

任何人都可以帮忙吗?

我已经解决了这个问题,现在

回答

1

您可以访问命令行参数在你的PHP脚本中预定义的全局变量。 在这种情况下您的$i将被找到为$argv[1]

试试这个脚本:

<?php 
global $argv; 
var_dump($argv); 
?> 

运行它php -f test.php A B C defgh产量:

array(5) { 
    [0]=> 
    string(8) "test.php" 
    [1]=> 
    string(1) "A" 
    [2]=> 
    string(1) "B" 
    [3]=> 
    string(1) "C" 
    [4]=> 
    string(5) "defgh" 
}