I need to adjust my shell script and write to $log
multiple times. Opening and closing the file repeatedly will cause an increase in runtime.
How can I write everything at once to the file, including all echo
statements defined in my script?
#!/bin/sh
log="loadlog.log"
for i in {1..10}
do
n=$((100*$i))
echo "## Users=$i requests=$n ##" >> $log
ab -n $n -c $i http://mainserver.com/index.html >> $log
ssh root@mainserver cat /proc/loadavg >> $log
echo "======" >> $log
done