如何设置定时自动采集?
手动采集效率低下,本文教你使用Linux crontab设置定时任务,实现每天自动采集更新。
什么是crontab?
crontab是Linux系统的定时任务工具,可以按照设定的时间自动执行命令。
苹果CMS V10定时采集
1. 获取采集URL
在苹果CMS后台,进入采集 → 自定义资源库,点击"采集当天",复制浏览器地址栏的URL。
示例:
```
https://yourdomain.com/admin/collect/api.html?ac=cj&rid=1&hour=24
```
2. 设置crontab
```
# 编辑crontab
crontab -e
# 每天凌晨2点执行采集
0 2 * * * curl -s "https://yourdomain.com/admin/collect/api.html?ac=cj&rid=1&hour=24" > /dev/null 2>&1
# 每天中午12点执行采集
0 12 * * * curl -s "https://yourdomain.com/admin/collect/api.html?ac=cj&rid=1&hour=24" > /dev/null 2>&1
```
3. 常用crontab时间设置
| 时间 | crontab表达式 |
|------|--------------|
| 每小时 | 0 * * * * |
| 每天凌晨2点 | 0 2 * * * |
| 每6小时 | 0 */6 * * * |
| 每周一凌晨 | 0 2 * * 1 |
海洋CMS定时采集
海洋CMS支持内置定时任务,在后台设置即可:
注意事项
高级:使用脚本采集
可以编写shell脚本,实现更复杂的采集逻辑:
```
#!/bin/bash
# collect.sh
LOG_FILE="/var/log/collection.log"
DATE=$(date +"%Y-%m-%d %H:%M:%S")
echo "[$DATE] 开始采集..." >> $LOG_FILE
# 采集资源站1
curl -s "https://yourdomain.com/admin/collect/api.html?ac=cj&rid=1" >> $LOG_FILE 2>&1
# 采集资源站2
curl -s "https://yourdomain.com/admin/collect/api.html?ac=cj&rid=2" >> $LOG_FILE 2>&1
echo "[$DATE] 采集完成" >> $LOG_FILE
```
设置crontab:
```
0 2,14 * * * /bin/bash /path/to/collect.sh
```