NameSilo

Cron

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch
Impact
23
Hi,

I did a search and haven't been able to find an answer.

Can I set up a cron job to run every 5mins, but only between midnight and 2am every day?

I think the answer is no.

I need to run a script once a day, but it takes more than 30 seconds to run and dies before it finishes. The script fetches a number of rss feeds, does some processing on them and inserts some info into a database.

I've changed the script to process only a few feeds each time it runs, but it means I need to run the script about 23 times to process all the feeds.

I need all of the info as early in the day as possible. I could run the script/cronjob every hour, but that means that some of the feeds won't be processed until later in the day, making them useless.

If I run the cronjob every 5 mins then all the feeds will be processed nice and early in the day, but I'll be inundated with 288 confirmation emails a day, because the cronjob will keep running even though there aren't any feeds for it to process.

Any thoughts or questions?

Cheers,
Richard
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
Around how many RSS feeds is it trying to process?
Also, what language is it written in?
 
0
•••
You can provide multiple values separated by commas:

This example will run every 5 minutes from midnight up to (but not including) 2 AM (and will not send you email)

0,5,10,15,20,25,30,35,40,45,50,55 0,1 * * * command > /dev/null 2>&1
 
Last edited:
1
•••
Around how many RSS feeds is it trying to process?
Also, what language is it written in?

About 600 feeds in total (I've broken it down into 23 feed chunks). PHP.

You can provide multiple values separated by commas:

This example will run every 5 minutes from midnight up to (but not including) 2 AM (and will not send you email)

0,5,10,15,20,25,30,35,40,45,50,55 0,1 * * * command > /dev/null 2>&1

Perfect... thanks!
 
0
•••
30 seconds must be the timeout for your scripts (PHP ?).
Have a look at the set_time_limit directive, if execution time can be overridden on your host.
 
0
•••
I think you need another cron to be involved - just to check if there are any new feeds. If there are - start the main script.
 
0
•••
Thanks for the response, Rob, but the feeds are updated constantly so they are always new.

I used enlytend's tip to make cron run like I wanted and it works perfect. I log everthing to a file, and when the last cron runs it sends me an email just so I can check everything was ok.
 
0
•••
Olitt โ€” high-converting AI websites, only from $1/moOlitt โ€” high-converting AI websites, only from $1/mo
Escrow.com
Spaceship
Domain Recover
CryptoExchange.com
Catchy
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back