发布时间2025-05-01 19:49
要实现下载完成后自动重启的需求,需要根据你的操作系统和具体使用场景来配置。以下是针对不同系统的技术方案,请根据你的实际情况选择:
batch
@echo off
check
timeout /t 60 >nul
if exist "D:Downloads.download" goto check
shutdown /r /t 60 /c "下载已完成,系统将在60秒后重启
1. 将上述代码保存为 `autoreboot.bat`
2. 创建任务计划:
1. 进入IDM设置 → 事件 → 创建新事件
2. 设置触发条件:
ini
[Trigger]
EventType=DownloadComplete
FileTypes=.jpg;.png;.webp
[Action]
ActionType=Execute
Command=shutdown.exe
Parameters=/r /t 300
bash
!/bin/bash
DOWNLOAD_DIR="$HOME/Downloads
TIMEOUT=300 5分钟无新文件视为完成
last_count=$(ls -l $DOWNLOAD_DIR | wc -l)
while true; do
sleep 60
new_count=$(ls -l $DOWNLOAD_DIR | wc -l)
if [ $new_count -eq $last_count ]; then
((counter++))
if [ $counter -ge $((TIMEOUT/60)) ]; then
sudo shutdown -r now
exit 0
fi
else
counter=0
last_count=$new_count
fi
done
1. 保存为 `/usr/local/bin/download_monitor.sh`
2. 添加执行权限:`chmod +x /usr/local/bin/download_monitor.sh`
3. 配置systemd服务:
ini
/etc/systemd/system/autoreboot.service
[Unit]
Description=Auto Reboot After Download
[Service]
ExecStart=/usr/local/bin/download_monitor.sh
Restart=always
[Install]
WantedBy=multi-user.target
1. 使用Python监控脚本:
python
import os
import time
from subprocess import call
download_path = "/path/to/downloads
inactivity_time = 1800 30分钟无变化
last_mtime = os.stat(download_path).st_mtime
while True:
time.sleep(300)
current_mtime = os.stat(download_path).st_mtime
if current_mtime > last_mtime:
last_mtime = current_mtime
else:
if time.time
if os.name == 'nt':
os.system("shutdown /r /t 60")
else:
os.system("sudo shutdown -r +1")
break
1. 权限要求:
2. 安全建议:
3. 文件识别技巧:
1. 使用监控软件(如Zabbix)设置触发器:
bash
trigger: Download folder modified in last 1h = 0
action: Execute remote reboot command
2. 容器化部署:
dockerfile
FROM alpine
RUN apk add no-cache inotify-tools
COPY auto_reboot.sh /
CMD ["/auto_reboot.sh"]
根据实际需求选择合适方案,建议先从简单的批处理/Shell脚本开始测试。如果是重要工作设备,请务必提前做好数据备份。
更多代购