Search code examples
cron

Using Crontab to Visit Multiple URLs with Wget


I have multiple sites and all this sites have cache plugin. I want to set crontab to all my these sites to clear cache. But I don't know how to do it with cron.

I use this code for only 1 site :

wget -O - "https://domain1/?action=wpfastestcache&type=clearcache&token=ABCD" >/dev/null 2>&1

So there are these sample sites, too :

https://domain1/?action=wpfastestcache&type=clearcache&token=ABCD
https://domain2/?action=wpfastestcache&type=clearcache&token=ABCD
https://domain3/?action=wpfastestcache&type=clearcache&token=ABCD
...

I don't want to set multiple cron for each site. I want to do it for all sites with 1 cron.


Solution

  • You can write a bash script to clear cache for all this sites from a single file

    vim cache-clear.sh

    #!/bin/bash
    wget -O - "https://domain1/?action=wpfastestcache&type=clearcache&token=ABCD" >/dev/null 2>&1
    wget -O - "https://domain2/?action=wpfastestcache&type=clearcache&token=ABCD" >/dev/null 2>&1
    wget -O - "https://domain3?action=wpfastestcache&type=clearcache&token=ABCD" >/dev/null 2>&1
    

    Then run this bash script from crontab , suppose you want to clear cache every 10 minutes

    crontab -e ---> to edit crontab

    */10 * * * *  bash cache-clear.sh >/dev/null 2>&1
    
    

    Run this script from crontab every 10th minute by adding above command in crontab