這裏是我的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