Make a lock of a cron

2

to see if someone gives me a hand, I have a cron that generates a feed of products in 26 languages, and it starts to happen that sometimes gives timeout I have happened to divide the file into 3 instead of having script.php have script1.php script2.php script3.php and launch the cron to script 1 but that the 2 does not start until the end of 1 so they do not get crushed, it would be something like this

51 01 * * * curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script1.php
51 01 * * * curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script2.php
51 01 * * * curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script2.php

Another option is to leave a considerable amount of time between them, but I do not know if it's the best option, does anyone know about it?

    
asked by Yus 11.07.2018 в 15:13
source

2 answers

1

I can think of this option:

51 01 * * * curl --max-time 1200 -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script1.php

Where the option --max-time defines in seconds the time that has to pass for the timeout to occur. I have put in the example 1200 seconds (20 minutes), but you can adjust it to what you consider appropriate

    
answered by 11.07.2018 в 15:35
0

and what if you put everything together in a single megacommand with & ?

51 01 * * * curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script1.php & curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script2.php & curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script3.php

so everything would be executed sequentially. Or if you want something more ordered, create a sheel script with the commands, say scripts.sh :

#!/bin/sh
curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script1.php
curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script2.php
curl -IH 'Host: mydomain.com' -H 'SSL-ON: on' http://127.0.0.1/script3.php

then you give execution permission with chmod +x scripts.sh and add to your crontab with:

51 01 * * * /larutadondeeste/scripts.sh
    
answered by 11.07.2018 в 17:41