'How can I pass a variable from a php script to a terminal command?

I have a terminal command that I've been running manually while I get my site up and running. It looks like this...

for ((i=1000; i<=2000; i++)); do  
curl -s --data '{"jsonrpc":"2.0", "method":"api.get_thing", "params":['$i'], "id":1}' https://api.site.com > /save_to_this_path/$i.txt; done

It works fine because I'm currently getting caught up to number 2000.

But once I get to 2000, I want to run a cron job every few minutes to get any new data.

I have a php script, /var/script.php

That script pulls this data from my database:

$myHighestRecord = 2000;
$apiHighestRecord = 2500;

In this example, the API is 500 records ahead of me, and I need to process those records. So I want my cron job to do something like...

curl /var/script.php

for ((i= $myHighestRecord; i<= $apiHighestRecord; i++)); do  
curl -s --data '{"jsonrpc":"2.0", "method":"api.get_thing", "params":['$i'], "id":1}' https://api.site.com > /save_to_this_path/$i.txt; done

I'm pretty sure this is possible but can't seem to figure out exactly how to do it. Any recommendations? Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source