【发布时间】:2012-11-03 10:30:21
【问题描述】:
这是我的 shell 脚本
#!/bin/bash
crawlers(){
nohup scrapy crawl a &
nohup scrapy crawl b &
wait $!
nohup scrapy crawl f &
nohup scrapy crawl g &
wait $!
nohup scrapy crawl h &
nohup scrapy crawl i &
wait $!
nohup scrapy crawl i &
nohup scrapy crawl j &
nohup scrapy crawl k &
wait $!
nohup scrapy crawl l &
nohup scrapy crawl m &
}
PATH=$PATH:/usr/local/bin
export PATH
python add_columns.py &
wait $!
crawlers &
wait $!
python final_script.py &
我想运行什么first add_columns.py 脚本
然后爬虫脚本(爬虫中的所有脚本都是异步的)
终于想运行final_script.py
但是使用上面的shell脚本
final_script.py 在结束前执行
nohup scrapy crawl l &
nohup scrapy crawl m &
虽然我在爬虫上等待
crawlers &
wait $!
最后,我如何才能在 crawlers() 方法中的所有作业完成后才能调用 final_script.py。
谢谢
【问题讨论】:
-
从除“scrapy crawl”之外的所有调用中删除“&”,删除所有对“wait”的调用,添加“for pid in $(jobs -p); do wait $pid || exit $ ?; done" 到函数 "crawlers" 结束