How do I run 100 iterations using a bash shell script? I want to know how long it will take to execute one command (start and end time). I want to keep track which iteration is currently running. I want to log each iteration. I have one automated script I need to run and log it.
for i in 1 2 3
do
command1
done
But I want to know how long it takes to complete one iteration - and write the information to a log file too!
You may use seq
in iteration as well:
for i in `seq 1 100`; do ... done
for ((i = 1; i <= 100; i++)); do
echo "--- Iteration #$i: $(date) ---"
time command1
done 2>&1 | tee timing.log
There's a lot going on here. What's happening?
for
loop iterates from 1 to 100 using C-style syntax.$i
in the echo printout prints the current iteration number.$(date)
inserts a timestamp into each printout.time
command runs a command and prints how long it took to execute.tee
, which saves a copy to timing.log
.2>&1
redirects stderr to stdout so that the log file will contain both regular output and error messages.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With