这里是我的shell脚本在Linux 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 &
什么我想运行第一 add_columns.py脚本
然后爬虫脚本(在爬虫的所有脚本都是异步)
终于想跑final_script.py
但使用上面的shell脚本
final_script.py已经结束
nohup scrapy crawl l &
nohup scrapy crawl m &
之前执行的,虽然我把等待cralwers
crawlers &
wait $!
最后,我怎么能achive调用final_script.py只有在crawlers()方法完成所有作业之后。
感谢
除“scrapy crawl”之外的所有调用中删除“&”,删除所有调用“等待”,添加“为pid $(jobs -p);等待$ pid || exit $ ?; done“到函数”crawlers“的末尾 – bobah