2

I have achieved benchmarking of two domains and plotting them in single graph. All is left now is to change the color of plotted lines for respective domains.

plot=$plot" 'benchmark_server_data_$counter.dat' using 10 smooth sbezier with lines title '$x' lc rgb 'blue'" # This is the line where i need to replace blue with array 

Like for example say, for domain1.org i want green color and for domain2.com i want blue. I think i need to create an array of colors and use for loop. I have tried but having lot of trouble.

while [ $i -lt 1 ]
do
what="http://domain1.org/,http://domain2.com/"
if [ -z "${what}" ];
then
echo "You did not specify a webserver to benchmark!"
else
OIFS=$IFS
IFS=','
arr=$what
counter=0
echo "set term png transparent truecolor" >> _temp.txt
#echo "set terminal png" >> _temp.txt
echo "set output 'out.png'" >> _temp.txt
echo "set title 'CodersHangout Webserver' tc rgb 'green' font 'Times-Roman, 20'" >> _temp.txt
echo "set size 1,1" >> _temp.txt
echo "set key left top tc rgb 'black' " >> _temp.txt
echo "set grid y " >> _temp.txt
echo "set xlabel 'Requests' font 'Times-Roman, 25' tc rgb 'green'" >> _temp.txt
echo "set ylabel 'Response time (ms)' font 'Times-Roman, 25' tc rgb 'green'" >> _temp.txt
echo "set xtics font 'Times-Roman, 20' tc rgb 'green'" >> _temp.txt
echo "set ytics font 'Times-Roman, 20' tc rgb 'green'" >> _temp.txt
echo "set object 1 rectangle from graph 0, graph 0 to graph 1, graph 1 behind fc rgbcolor 'gray' fs noborder" >> _temp.txt
plot="plot"
    for x in $arr
    do
            echo "> Running benchmark for $x"
            if [ "$counter" -gt 0 ];
            then
            plot=$plot","
            fi               
            plot=$plot" 'benchmark_server_data_$counter.dat' using 10 smooth sbezier with lines title '$x' lc rgb 'blue'" #Need to change the color of curve for different domains!
            ab -n $total -c $concurrent -k -g benchmark_server_data_$counter.dat -H 'Accept-Encoding:gzip,deflate' $x           
            counter=$(( counter + 1 ))      

    done
IFS=$OIFS
echo $plot >> _temp.txt
gnuplot _temp.txt
rm _temp.txt
rm benchmark_server_data_*
exec /opt/lampp/htdocs/serverstat/autoftp.sh
exit
fi
i=1
done
3
  • 1
    Isn't it more of a bash question cause i just need to make an array and loop through that array containing color names plot=$plot" 'benchmark_server_data_$counter.dat' using 10 smooth sbezier with lines title '$x' lc rgb 'blue'" This is the line where i need to replace blue with array name. Commented Jul 17, 2013 at 13:48
  • 1
    I took you at face value : "All is left now is to change the color of plotted lines for respective domains.". Better to highlight (in the body of your question) that info. +1 for excellent first question. Sorry I don't have time right now to help , but keep posting and Good luck. Commented Jul 17, 2013 at 14:10
  • 1
    Thank you @shellter I will keep a check. You can always come back and help. I can wait. Since, no one else seems interested in this :( Commented Jul 17, 2013 at 18:48

1 Answer 1

1

You can use something like this:

#!/usr/bin/bash

arr=(http://domain1.org/ http://domain2.com/)
colour=(blue green)
for ((counter=0; counter<${#arr[@]}; ++counter));{
  echo ${arr[counter]}, \'${colour[counter]}\'
}

Output:

http://domain1.org/, 'blue'
http://domain2.com/, 'green'

I would not recommend to redefine IFS as later on it can cause hard-to-detect problems.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for replying first of all. I have not tried it but it looks fine to me. Thought it needs lot of modifications but this gave me a good idea on how to do it. Great! Thanks a lot!
@Bhavyanshu: The pleasure is mine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.