#!/bin/bash lock_file="auto_install.lock" cleaner_script="auto_cleaner.sh" cron_command="sh $(pwd)/$cleaner_script $(pwd)/" # 检查是否已安装 if [ -f "$lock_file" ]; then echo "auto_cleaner.sh任务已安装,如需重新安装,请先删除$lock_file文件" exit 1 fi # 获取当前目录的绝对路径 current_dir=$(pwd)/ # 检查auto_cleaner.sh文件是否存在 if [ ! -f "$current_dir$cleaner_script" ]; then echo "未找到$current_dir$cleaner_script文件,退出本次安装" exit 1 fi # 检查是否已存在定时任务 existing_cron=$(crontab -l | grep -F "$cron_command") if [ -n "$existing_cron" ]; then echo "auto_cleaner.sh任务已安装,退出本次安装" exit 1 fi # 创建安装标记文件 timestamp=$(date +"%Y-%m-%d %H:%M:%S") echo "安装时间: $timestamp" > "$lock_file" # 创建定时任务 (crontab -l 2>/dev/null; echo "*/10 * * * * $cron_command") | crontab - echo "auto_cleaner.sh任务安装完毕" exit 0