我写了这个非常丑陋的 shell 脚本,但在某一时刻却运行得很好。现在它工作一两分钟然后退出。我知道它很丑,但它有效,所以我从未改变它。谁能告诉我出了什么问题吗?任何帮助是极大的赞赏 :)
#!/bin/bash
echo "Starting..."
timestamphour=`date +%F_%H`
mkdir /Some/Directory1
mkdir /Some/Directory2
mkdir /Some/Directory3
mkdir /Some/Directory4
mkdir /Some/Directory5
mkdir /Some/Directory6
mkdir /Some/Directory7
mkdir /Some/Directory8
mkdir /Some/Directory9
#This could be done in one step
mkdir /Some/Directory1/$timestamphour
mkdir /Some/Directory2/$timestamphour
mkdir /Some/Directory3/$timestamphour
mkdir /Some/Directory4/$timestamphour
mkdir /Some/Directory5/$timestamphour
mkdir /Some/Directory6/$timestamphour
mkdir /Some/Directory7/$timestamphour
mkdir /Some/Directory8/$timestamphour
mkdir /Some/Directory9/$timestamphour
for i in {1..3600}
do
#timestampmin=`date +%F_%H-%M`
timestampsec=`date +%F_%H-%M-%S`
sudo curl -o /Some/Directory1/$timestamphour/$timestampsec.jpg http://some.address.at.some:port1/jpg/image.jpg &
sudo curl -o /Some/Directory2/$timestamphour/$timestampsec.jpg http://some.address.at.some:port2/jpg/image.jpg &
sudo curl -o /Some/Directory3/$timestamphour/$timestampsec.jpg http://some.address.at.some:port3/jpg/image.jpg &
sudo curl -o /Some/Directory4/$timestamphour/$timestampsec.jpg http://some.address.at.some:port4/jpg/image.jpg &
sudo curl -o /Some/Directory5/$timestamphour/$timestampsec.jpg http://some.address.at.some:port5/jpg/image.jpg &
sudo curl -o /Some/Directory6/$timestamphour/$timestampsec.jpg http://some.address.at.some:port6/jpg/image.jpg &
sudo curl -o /Some/Directory7/$timestamphour/$timestampsec.jpg http://some.address.at.some:port7/jpg/image.jpg &
sudo curl -o /Some/Directory8/$timestamphour/$timestampsec.jpg http://some.address.at.some:port8/jpg/image.jpg &
sudo curl -o /Some/Directory9/$timestamphour/$timestampsec.jpg http://some.address.at.some:port9/jpg/image.jpg &
sleep 1
done
答案1
尝试使用wait
而不是sleep
.wait
将等待所有后台进程完成然后继续,而睡眠只是延迟一秒钟。
看看是否wait
有效