bash + run script in the loop cycle

we need to run the run.sh on each 10 steps

for x in {1..100} ; do
  sleep 1
  /tmp/run.sh
done

so finally run.sh will run 10 times

how we can do that?

other example ( in this case run.sh will run 20 times )

for x in {1..200} ; do
  sleep 1
  /tmp/run.sh
done

Answer

You just have to test if the value of x can be divided by 10 :

for x in {0..100} ; do
    if (( x % 10 == 0 ))
    then
        /tmp/run.sh
    fi
    sleep 1
done

Leave a Reply

Your email address will not be published. Required fields are marked *