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 iteratio
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.