0

I want to run many tasks which are defined is a batch file, for example

task.sh

for i in 1 2 3 4 5
do
    setsid python main.py 1>data/${i}_a.log 2>&1
    sleep 3
done
echo "OK 1"


for i in 1 2 3 4 5
do
    setsid python main.py  1>data/${i}_b.log 2>&1
    sleep 3
done
echo "OK 2"

However, when I run task.sh, it got stuck and it seems that it did not run. How can I fix it?

  • You set it to sleep 3 seconds every iteration. Is that why it's taking so long? – sergiuser Jul 22 at 13:57
  • Remove 1>data/${i}_a.log 2>&1 and you might see error messages on your screen. – WinEunuuchs2Unix Jul 22 at 17:16
  • @WinEunuuchs2Unix Thank you, but there are no errors. I think in shell, the setsid can not make it run in the background and only the former process exits can the later process run. When I run for loop in command and it can run. – GoingMyWay Jul 23 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.