T06 · System Persistence
- Location
main_v3.py:78- Finding
Persistent Scheduled Execution Through System and OpenClaw Cron
- Content
View full analysis
> {LOG_FILE} 2>&1 """) os.chmod(script_path, 0o755) cron_line = "55 3 * * * {0}".format(script_path) try: existing = os.popen("crontab -l 2>/dev/null").read() except: existing = "" lines = [line for line in existing.split("\n") if "chat-history" not in line and line.strip()] base_cron = "\n".join(lines) + "\n" new_cron = base_cron + "\n" + cron_line + "\n" import tempfile with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: f.write(new_cron) temp_file = f.name os.system(f"crontab {temp_file}") os.unlink(temp_file) ``` ```python # main_v3.py:78-101 def setup_cron(): """设置 OpenClaw 定时任务""" try: skill_dir = os.path.dirname(os.path.abspath(__file__)) main_py_path = os.path.join(skill_dir, "main_v3.py") if check_cron_setup(): return True, "定时任务已存在" result = subprocess.run( [ "openclaw", "cron", "add", "--name", "chat-history-archive", "--cron", "59 23 * * *", "--system-event", f"Chat History: 请运行 python3 {main_py_path} --archive", "--session", "main" ], capture_output=True, text=True, timeout=15 ) if result.returncode == 0: log_message("成功设置 OpenClaw cron 任务") return True, "suc ...[truncated 1987 chars]- Remediation
View remediation
