LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script to test IOPS on multiple mounted disk (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-test-iops-on-multiple-mounted-disk-4175595622/)

limdel 12-17-2016 04:49 AM

script to test IOPS on multiple mounted disk
 
Hi,
My goal is to have a single script that would output something like this:
Code:

sas15kr1001-1 =197 MB/s
sas15kr1001-16 =209 MB/s

on several disk by running the 2 following commands
Code:

dd if=/dev/zero of=/sas15kr1001/test.io bs=64k count=1k conv=fdatasync
dd if=/dev/zero of=/sas15kr1001/test.io bs=64k count=16k conv=fdatasync

where sas15kr1001 is the mount point of a disk and "1" and "16" is the number thousand block of 64k written on the disk.
So i wrote this script
Code:

#!/bin/bash
adisk=( sas15kr1001 sas10kr501 sas15kr502 r10a r10b )
for i in "${adisk[@]}"
do
#      echo $i
        acount=( "1" "16" )
        for c in "${acount[@]}"
        do
                dd if=/dev/zero of=/`$i`/test.io bs=64k count=`$c`k conv=fdatasync 2>&1 |& awk '/copied/ {print "'$i'- '$c'=" $8 " "  $9}'
        done
done

While the command
Code:

dd if=/dev/zero of=/sas15kr1001/test.io bs=64k count=1k conv=fdatasync  2>&1 |& awk '/copied/ {print "sas15kr1001-1=" $8 " " $9}'
return
Code:

sas15kr1001-1=181 MB/s
when i run the script, the output is quite weird
Code:

./testio.sh
./testio.sh: line 9: sas15kr1001: command not found
./testio.sh: line 9: 1: command not found
sas15kr1001- 1=188 MB/s
./testio.sh: line 9: sas15kr1001: command not found
./testio.sh: line 9: 16: command not found
sas15kr1001- 16=200 MB/s

any one can point me where i get it wrong ?
Cheers

AwesomeMachine 12-17-2016 05:42 AM

I think you must change the tick marks to quotes. Ticks indicate the output of a command. `ls` is the output of ls.

MadeInGermany 12-17-2016 06:21 AM

Yes, backticks run their contents as a subshell i.e. shell commands.
If not yet in quotes, quote the variables
Code:

of=/"$i"/test.io bs=64k count="$c"k
If they are in quotes already you might need to { } them
Code:

"of=/$i/test.io" bs=64k "count=${c}k"
--
Why array variables?
Code:

#!/bin/bash
for i in sas15kr1001 sas10kr501 sas15kr502 r10a r10b
do
#      echo $i
        for c in 1 16
        do
...

Array variables make sense if you want to do complex operations on the elements, like removing/inserting/rearranging/changing them.

limdel 12-18-2016 08:33 PM

Thank you guys for your valuable feedback.
Here the final script for further ref.
Code:

#!/bin/bash
for i in sas15kr1001 sas10kr501 sas15kr502 r10a r10b
do
#      echo $i
        for c in 1 16
        do
                siz=`expr $c \* 64000`
                dd if=/dev/zero of=/"$i"/test.io bs=64k count="$c"k conv=fdatasync 2>&1 |& awk '/copied/ {print "'$i' \t '$siz' \t " $8 " "  $9}'
        done
done


MadeInGermany 12-19-2016 07:24 AM

Bash's builtin arithmetic is as good as the one in expr, but much more efficient.
Replace
Code:

                siz=`expr $c \* 64000`
by
Code:

                siz=$(( c * 64000 ))


All times are GMT -5. The time now is 03:04 AM.