1

I have a bash script which runs in cron every day at 1:01am the bash script is:

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

This issue is that I don't know if $i is being passed as a argument to the php script. Am I doing something wrong ? If I put the $i within "" it says it cannot find the file because the file name becomes /mnt/www/bin/scheduled/import_client.php 2 for example

Could anyone help ?

1 Answer 1

1

You can access the command line arguments in your PHP script in the predefined global variable $argv. Your $i in this case would be found as $argv[1].

Try this script:

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

Running it with php -f test.php A B C defgh yields:

array(5) {
  [0]=>
  string(8) "test.php"
  [1]=>
  string(1) "A"
  [2]=>
  string(1) "B"
  [3]=>
  string(1) "C"
  [4]=>
  string(5) "defgh"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.