使用 Crontab 以 Wget 访问多个 URL

Using Crontab to Visit Multiple URLs with Wget

我有多个网站,所有这些网站都有缓存插件。我想为所有这些站点设置 crontab 以清除缓存。但是我不知道怎么用cron.

我仅将此代码用于 1 个站点:

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

所以也有这些示例站点:

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

我不想为每个站点设置多个 cron。我想为所有具有 1 个 cron 的站点执行此操作。

您可以编写 bash 脚本来从单个文件中清除所有这些站点的缓存

vim缓存-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

然后 运行 这个来自 crontab 的 bash 脚本,假设你想每 10 分钟清除一次缓存

crontab -e ---> 编辑 crontab

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

运行 通过在 crontab 中添加上述命令,每 10 分钟从 crontab 中获取此脚本