在 Linux 上“定时 fetch”(定时拉取数据/代码/文件)常见有几种场景,下面按最常见用法给你说明。
如果你说的是定时执行 fetch / git fetch / wget / curl 等命令,最常用的是 crontab。
crontab -e
每 10 分钟执行一次 git fetch
*/10 * * * * cd /path/to/repo && git fetch >> /var/log/fetch.log 2>&1
每天凌晨 3 点执行 fetch 脚本
0 3 * * * /home/user/fetch.sh
分 时 日 月 周
* * * * *
如果 fetchlinux 是一个自定义脚本或程序:
# 给执行权限
chmod +x fetchlinux
# 定时运行
*/5 * * * * /path/to/fetchlinux
适合服务器环境。
# /etc/systemd/system/fetchlinux.service
[Unit]
Description=Fetch Linux Data
[Service]
ExecStart=/path/to/fetchlinux
# /etc/systemd/system/fetchlinux.timer
[Unit]
Description=Run fetchlinux every hour
[Timer]
OnCalendar=hourly
Persistent=true
[Install]
WantedBy=timers.target
systemctl enable --now fetchlinux.timer
*/30 * * * * cd /repo && git fetch && git pull
0 */6 * * * wget -O data.zip https://example.com/data.zip
tail -f /var/log/cron
如果你能具体说一下:
我可以直接给你完整可复制的配置。