0

I would like to know of it is possible to execute a Cron job every 30 seconds and increment an argument from a value (1 for exemple) to another (50000) :
Like :

wget https://mon-url.com/file/cron.php?id=1 >/dev/null 2>&1 
wget https://mon-url.com/file/cron.php?id=2 >/dev/null 2>&1 
wget https://mon-url.com/file/cron.php?id=3 >/dev/null 2>&1 
wget https://mon-url.com/file/cron.php?id=4 >/dev/null 2>&1 
....
wget https://mon-url.com/file/cron.php?id=50000 >/dev/null 2>&1

Is there any command to do that programaticaly ?
Thanks

Pablo DelaNoche
  • 677
  • 1
  • 9
  • 28
  • It does not really have to do something with PHP, something you might be looking for: https://stackoverflow.com/questions/3639415/variables-in-crontab You could also write a shell script doing the `wget` and storing the value somewhere which is executed by cron. – Eknoes Feb 20 '18 at 19:55
  • 1
    You could potentially store this increment in a database and request and update it everytime it's called again if you just wanted a typical +1. –  Feb 20 '18 at 20:15
  • @ConorReid It's an brillant idea ! Thanks – Pablo DelaNoche Feb 20 '18 at 20:20
  • That’s a lot of queries just to iterate over a simple loop. Single bash script would do much better. – Mike Doe Feb 20 '18 at 20:34
  • @Mike any lead to help me with your bash script ? – Pablo DelaNoche Feb 20 '18 at 20:42
  • My bash script? :) Simple loop will do, there are lots of examples on the net and SO. Just make sure you create some sort of a PID file to prevent the script of running twice or more should it be run too quickly. – Mike Doe Feb 20 '18 at 21:14

3 Answers3

0

As suggested before i'd rather go with bash script like this (or similar):

#!/bin/bash
i=1;
while [ $i -le 5 ]
do
    wget https://mon-url.com/file/cron.php?id=$i >/dev/null 2>&1
    i=$(($i+1));
    sleep 30
done

Regards. Ps. change 5 after -le to whathever you need

Bartek M
  • 1
  • 1
0

Look here below you want:

$x = 1; // You value set to minim
$y = 50000; // Your value set to maxim

while($x <= $y) {
  echo "wget https://mon-url.com/file/cron.php?id=$x  >/dev/null 2>&1";
  $x++;
}

You can use this in your script for cron jobs. Good look!

AdyDev
  • 106
  • 7
0

Perhaps u can just export your counter incrementing it by one every time

COUNTER=0
*/30 * * * * wget https://mon-url.com/file/cron.php?id="$COUNTER" >/dev/null 2>&1 && export COUNTER=$((COUNTER+1))
avpav
  • 452
  • 4
  • 7