run_update_published_articles_daily.sh 1.0 KB

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. # 获取当前日期,格式为 YYYY-MM-DD
  3. CURRENT_DATE=$(date +%F)
  4. # 日志文件路径,包含日期
  5. LOG_FILE="/root/luojunhui/logs/update_published_articles_task_log_$CURRENT_DATE.txt"
  6. # 重定向整个脚本的输出到带日期的日志文件
  7. exec >> "$LOG_FILE" 2>&1
  8. if pgrep -f "python3 updatePublishedMsgDaily.py" > /dev/null
  9. then
  10. echo "$(date '+%Y-%m-%d %H:%M:%S') - updatePublishedMsgDaily.py is running"
  11. else
  12. echo "$(date '+%Y-%m-%d %H:%M:%S') - trying to restart updatePublishedMsgDaily.py"
  13. cd /root/luojunhui/LongArticlesJob
  14. source /root/miniconda3/etc/profile.d/conda.sh
  15. conda activate tasks
  16. current_time=$(date +%H:%M)
  17. target_time="19:00"
  18. if [[ "$current_time" < "$target_time" ]]; then
  19. nohup python3 updatePublishedMsgDaily.py --run_task update >> "${LOG_FILE}" 2>&1 &
  20. else
  21. nohup python3 updatePublishedMsgDaily.py >> "${LOG_FILE}" 2>&1 &
  22. echo "$(date '+%Y-%m-%d %H:%M:%S') - successfully restarted updatePublishedMsgDaily.py"
  23. fi
  24. fi