【问题标题】:cronjob wait issuecronjob 等待问题
【发布时间】:2012-10-06 07:04:35
【问题描述】:

我在 ubuntu 服务器上运行 python 脚本,尽管 cronjob bellow 是我的 bash 文件内容

#!/bin/bash
cd /home/ubuntu/
PATH=$PATH:/usr/local/bin
export PATH
nohup scrapy crawl first_job &
nohup scrapy crawl second_job &
nohup scrapy crawl third_job &
wait $(pgrep third_job)
nohup scrapy crawl fourth_job &

我想要的是 fourth_jobthird_job 完成后立即开始执行

但是

目前即使third_job完成,fouth_job等待first_jobsecond_job完成

提前致谢

【问题讨论】:

  • 您确定 pgrep third_job 只返回 third_jobpid 而不是所有三个作业的 pids

标签: linux bash ubuntu cron


【解决方案1】:

获取最后一个后台进程的 PID 的更安全的方法是记住 $! 的值:

nohup scrapy crawl third_job &
PID=$!
wait $PID

【讨论】:

  • 感谢您的回答如果我想等待第二个作业,例如第二个作业结束,第四个开始,无论 1,3 已完成还是仍在运行?
  • @akhterwahab:只需在您要等待的工作开始后立即输入PID=$!
猜你喜欢
  • 1970-01-01
  • 2011-11-11
  • 2017-12-27
  • 1970-01-01
  • 2021-10-11
  • 2014-10-27
  • 1970-01-01
  • 1970-01-01
  • 2016-10-12
相关资源
最近更新 更多