run_get_off_videos_three_times_per_day.sh 881 B

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. # 获取当前日期,格式为 YYYY-MM-DD
  3. CURRENT_DATE=$(date +%F)
  4. # 日志文件路径,包含日期
  5. LOG_FILE="/root/luojunhui/logs/get_off_videos_task_log_$CURRENT_DATE.txt"
  6. # 重定向整个脚本的输出到带日期的日志文件
  7. exec >> "$LOG_FILE" 2>&1
  8. if pgrep -f "python3 getOffVideosDaily.py" > /dev/null
  9. then
  10. echo "$(date '+%Y-%m-%d %H:%M:%S') - getOffVideosDaily.py is running"
  11. else
  12. echo "$(date '+%Y-%m-%d %H:%M:%S') - trying to restart getOffVideosDaily.py"
  13. # 切换到指定目录
  14. cd /root/luojunhui/LongArticlesJob
  15. # 激活 Conda 环境
  16. source /root/miniconda3/etc/profile.d/conda.sh
  17. conda activate tasks
  18. # 在后台运行 Python 脚本并重定向日志输出
  19. nohup python3 getOffVideosDaily.py >> "${LOG_FILE}" 2>&1 &
  20. echo "$(date '+%Y-%m-%d %H:%M:%S') - successfully restarted getOffVideosDaily.py"
  21. fi