更新 Cronie 定时任务配置方法

This commit is contained in:
CallMeR
2026-08-14 23:35:07 +08:00
parent 9beb1fba6a
commit 2fadc58a84
7 changed files with 70 additions and 80 deletions
+1 -1
View File
@@ -160,7 +160,7 @@ $ apt full-upgrade
$ apt update $ apt update
## 安装系统软件 ## 安装系统软件
$ apt install btop lm-sensors curl tmux neovim unattended-upgrades powermgmt-base sshguard knot-dnsutils $ apt install btop lm-sensors curl tmux cronie neovim unattended-upgrades powermgmt-base sshguard knot-dnsutils
## 安装 CPU 调度调整工具 ## 安装 CPU 调度调整工具
$ apt install linux-cpupower $ apt install linux-cpupower
+7 -12
View File
@@ -230,21 +230,16 @@ $ watch -d sensors
参数表示每月 `1``16` 号的 `02:30` 执行系统重启命令。 参数表示每月 `1``16` 号的 `02:30` 执行系统重启命令。
```bash 执行以下命令创建 Cronie 系统定时任务文件。
## 查看系统定时任务
$ crontab -l
## 编辑系统定时任务,编辑器选择 nano
$ crontab -e
```
在配置文件末尾,增加以下内容。
```bash ```bash
## 定时任务配置项 ## 创建 PVE 定时重启任务
$ tee /etc/cron.d/pve-reboot >/dev/null <<'EOF'
30 2 1,16 * * /usr/sbin/shutdown --reboot now 30 2 1,16 * * root /usr/sbin/shutdown --reboot now
EOF
## 设置定时任务文件权限
$ chmod 0644 /etc/cron.d/pve-reboot
``` ```
系统全局定时任务排期状态可使用以下命令进行查看。 系统全局定时任务排期状态可使用以下命令进行查看。
+7 -12
View File
@@ -384,21 +384,16 @@ $ sudo systemctl status apt-daily-upgrade.timer
本步骤为可选操作,主要设置系统定时重启。 本步骤为可选操作,主要设置系统定时重启。
```bash 执行以下命令创建 Cronie 系统定时任务文件。
## 查看系统定时任务
$ sudo crontab -l
## 编辑系统定时任务,编辑器选择 nano
$ sudo crontab -e
```
在配置文件末尾,增加以下内容。
```bash ```bash
## 定时任务配置项 ## 创建 Guest OS 定时重启任务
$ sudo tee /etc/cron.d/guest-os-reboot >/dev/null <<'EOF'
30 4 8,24 * * /usr/sbin/shutdown --reboot now 30 4 8,24 * * root /usr/sbin/shutdown --reboot now
EOF
## 设置定时任务文件权限
$ sudo chmod 0644 /etc/cron.d/guest-os-reboot
``` ```
### 1.10.清理系统 ### 1.10.清理系统
+22 -28
View File
@@ -158,21 +158,16 @@ $ sudo snap set system refresh.timer=mon,2:30,,fri,2:30
本步骤为可选操作,主要用于设置 `Adguard Home` 定时重启。 本步骤为可选操作,主要用于设置 `Adguard Home` 定时重启。
```bash 执行以下命令创建 Cronie 系统定时任务文件。
## 查看系统定时任务
$ sudo crontab -l
## 编辑系统定时任务,编辑器选择 nano
$ sudo crontab -e
```
在配置文件末尾,增加以下内容。
```bash ```bash
## 定时任务配置项 ## 创建 Adguard Home 定时重启任务
$ sudo tee /etc/cron.d/adguard-home-restart >/dev/null <<'EOF'
30 4 * * * /usr/bin/snap restart adguard-home 30 4 * * * root /usr/bin/snap restart adguard-home
EOF
## 设置定时任务文件权限
$ sudo chmod 0644 /etc/cron.d/adguard-home-restart
``` ```
## 6. SmartDNS ## 6. SmartDNS
@@ -264,31 +259,30 @@ $ sudo /usr/local/bin/smartdns-cnlist
本步骤为可选操作,主要用于设置 `SmartDNS` 定时更新附加配置文件和定时重启。 本步骤为可选操作,主要用于设置 `SmartDNS` 定时更新附加配置文件和定时重启。
```bash
## 编辑系统定时任务,编辑器选择 nano
$ sudo crontab -e
```
若使用了 `SmartDNS` 加速规则的安装脚本,由于脚本自带服务重启功能,因此定时任务可设置如下。 若使用了 `SmartDNS` 加速规则的安装脚本,由于脚本自带服务重启功能,因此定时任务可设置如下。
```bash ```bash
## 定时任务配置项 ## 创建 SmartDNS 规则更新任务
$ sudo tee /etc/cron.d/smartdns-rules-update >/dev/null <<'EOF'
20 9 * * * /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf 20 9 * * * root /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf
30 9 * * * root /usr/local/bin/smartdns-cnlist
30 9 * * * /usr/local/bin/smartdns-cnlist EOF
## 设置定时任务文件权限
$ sudo chmod 0644 /etc/cron.d/smartdns-rules-update
``` ```
若仅需定时重启 `SmartDNS` 服务,定时任务可调整如下 若仅需定时重启 `SmartDNS` 服务,可使用以下命令覆盖该定时任务文件
```bash ```bash
## 定时任务配置项 ## 创建 SmartDNS 规则更新任务
$ sudo tee /etc/cron.d/smartdns-rules-update >/dev/null <<'EOF'
20 9 * * * /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf 20 9 * * * root /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf
30 9 * * * root /usr/bin/systemctl restart smartdns.service
30 9 * * * /usr/bin/systemctl restart smartdns.service EOF
## 设置定时任务文件权限
$ sudo chmod 0644 /etc/cron.d/smartdns-rules-update
``` ```
### 6.3. SmartDNS 主配置 ### 6.3. SmartDNS 主配置
+7 -9
View File
@@ -748,18 +748,16 @@ $ sudo tailscale set --auto-update=false
本步骤为可选操作,主要用于设置 TS 定时重启。 本步骤为可选操作,主要用于设置 TS 定时重启。
```bash 执行以下命令创建 Cronie 系统定时任务文件。
## 编辑系统定时任务,编辑器选择 nano
$ sudo crontab -e
```
在配置文件末尾,增加以下内容。
```bash ```bash
## 定时任务配置项 ## 创建 Tailscale 定时重启任务
$ sudo tee /etc/cron.d/tailscale-restart >/dev/null <<'EOF'
30 10 * * * /usr/bin/systemctl restart tailscaled.service 30 10 * * * root /usr/bin/systemctl restart tailscaled.service
EOF
## 设置定时任务文件权限
$ sudo chmod 0644 /etc/cron.d/tailscale-restart
``` ```
至此,TS 服务器已配置完成。 至此,TS 服务器已配置完成。
+11 -8
View File
@@ -1,18 +1,21 @@
## 下载加速规则安装脚本 ## 下载加速规则安装脚本
$ sudo curl -LR -o /usr/local/bin/dnsmasq-plugin.sh https://gitee.com/felixonmars/dnsmasq-china-list/raw/master/install.sh $ sudo curl -LR -o /usr/local/bin/dnsmasq-cnlist https://gitee.com/felixonmars/dnsmasq-china-list/raw/master/install.sh
## 设置脚本可执行权限 ## 设置脚本可执行权限
$ sudo chmod +x /usr/local/bin/dnsmasq-plugin.sh $ sudo chmod +x /usr/local/bin/dnsmasq-cnlist
## 设置脚本文件防篡改 ## 设置脚本文件防篡改
$ sudo chattr +i /usr/local/bin/dnsmasq-plugin.sh $ sudo chattr +i /usr/local/bin/dnsmasq-cnlist
## 执行脚本 ## 执行脚本
$ sudo /usr/local/bin/dnsmasq-plugin.sh $ sudo /usr/local/bin/dnsmasq-cnlist
## 设置 crontab ## 创建 Dnsmasq 规则更新任务
$ sudo tee /etc/cron.d/dnsmasq-rules-update >/dev/null <<'EOF'
25 9 * * * root /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/dnsmasq.d/anti-ad.dnsmasq.conf https://anti-ad.net/anti-ad-for-dnsmasq.conf
35 9 * * * root /usr/local/bin/dnsmasq-cnlist
EOF
25 9 * * * /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/dnsmasq.d/anti-ad.dnsmasq.conf https://anti-ad.net/anti-ad-for-dnsmasq.conf ## 设置定时任务文件权限
$ sudo chmod 0644 /etc/cron.d/dnsmasq-rules-update
35 9 * * * /usr/local/bin/dnsmasq-plugin.sh
+15 -10
View File
@@ -1,14 +1,19 @@
# This configuration file is customized by fox, ## 创建 SmartDNS 规则更新任务
# Optimize SmartDNS crontab for local DNS server. $ sudo tee /etc/cron.d/smartdns-rules-update >/dev/null <<'EOF'
20 9 * * * root /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf
30 9 * * * root /usr/local/bin/smartdns-cnlist
EOF
20 9 * * * /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf ## 设置定时任务文件权限
$ sudo chmod 0644 /etc/cron.d/smartdns-rules-update
30 9 * * * /usr/bin/systemctl restart smartdns.service ## 或仅需重启 SmartDNS 服务本身
## 创建 SmartDNS 规则更新任务
$ sudo tee /etc/cron.d/smartdns-rules-update >/dev/null <<'EOF'
20 9 * * * root /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf
30 9 * * * root /usr/bin/systemctl restart smartdns.service
EOF
## Or when the SmartDNS China List installer is installed ## 设置定时任务文件权限
$ sudo chmod 0644 /etc/cron.d/smartdns-rules-update
20 9 * * * /usr/bin/curl --retry-connrefused --retry 5 --retry-delay 5 --retry-max-time 60 -fsSLR -o /etc/smartdns.d/anti-ad.smartdns.conf https://anti-ad.net/anti-ad-for-smartdns.conf
30 9 * * * /usr/local/bin/smartdns-cnlist