zcav capture
1 2 #!/bin/bash 3 # 4 # ZCAV Capture btodd3 5 # version 6 ver=1.3 7 8 # plot temp file 9 pscript=/tmp/plotscript 10 11 function make_script () { 12 echo '# zcav plot script' >> $pscript 13 echo >> $pscript 14 echo '# plot format' >> $pscript 15 #comment terminal line out and uncomment pause line below to send plot to screen 16 echo set terminal png picsize 1024 768 >> $pscript 17 echo set key outside below >> $pscript 18 echo set key box >> $pscript 19 echo set grid x y2 >> $pscript 20 echo set xtics >> $pscript 21 echo set mxtics >> $pscript 22 echo set ytics >> $pscript 23 echo set mytics >> $pscript 24 echo set y2tics nomirror >> $pscript 25 echo >> $pscript 26 echo '# labels' >> $pscript 27 echo set title '"Zoned Constant Angular Velocity (ZCAV) Results\n'${mfg}' '${capacity}' '${interface}'\nModel - '${model}'\nSerial Number - '${serialnum}'"' >> $pscript 28 echo set xlabel "'Block #'" >> $pscript 29 echo set ylabel "'K/s'" >> $pscript 30 echo set y2label "'Read Time'" >> $pscript 31 echo set label "'Plot Style - "${style}"'" at screen 0.07, screen 0.01 >> $pscript 32 echo >> $pscript 33 echo '# plot it' >> $pscript 34 echo plot "'${zdata}'" using 1:2 "${ptype}" title "'K/s'" axis x1y1 , "'${zdata}'" using 1:3 "${ptype}" title "'Time'" axis x1y2 >> $pscript 35 echo >> $pscript 36 #echo pause -1 >> $pscript 37 echo '# undo what was done' >> $pscript 38 echo reset >> $pscript 39 } 40 41 function demo_mode () { 42 mfg=demo 43 model=demo 44 capacity=demo 45 interface=demo 46 serialnum=demo 47 device=demo 48 zdata="/usr/local/bin/zsample.dat" 49 zplot=/root/Desktop/demo-zcavplot.png 50 echo "--- zcavcap Demo Mode ---" 51 read -p "Enter plot style (1-Normal, 2-Bezier, 4-Unique): " demo_plot_style 52 53 # plot style 54 case "$demo_plot_style" in 55 1) 56 ptype="" 57 style="Normal" 58 ;; 59 2) 60 ptype="smooth bezier" 61 style="Bezier" 62 ;; 63 4) 64 ptype="smooth unique" 65 style="Unique" 66 ;; 67 *) 68 ptype="" 69 style="Normal" 70 ;; 71 esac 72 73 read -p "The following data file will be plotted. (/usr/local/bin/zsample.dat)" 74 make_script 75 echo "Generating Plot..." 76 gnuplot> $zplot $pscript 77 read -p "Plot script was not deleted. Do you want to delete it now? (1-Yes, 2-No): " pdelete 78 79 # delete plot script or not 80 case "$pdelete" in 81 1) 82 rm -f $pscript 83 exit 0 84 ;; 85 2) 86 exit 0 87 ;; 88 esac 89 } 90 91 # demo mode or not? 92 if [ -n "$1" ] && [ "$1" == "--demo" ] ; then 93 demo=1 94 else 95 demo=0 96 fi 97 98 if [ $demo -ne 0 ]; then 99 demo_mode 100 fi 101 102 function replot () { 103 echo "--- zcavcap Replot ---" 104 read -p "Enter the unit's Manufacturer: " mfg 105 read -p "Enter the unit's model: " model 106 read -p "Enter the unit's capacity (i.e. 80GB): " capacity 107 read -p "Enter the unit's interface type (i.e. SAS, SATA): " interface 108 read -p "Enter the unit's serial number: " serialnum 109 read -p "Enter the data file to plot (i.e. /root/Dekstop/sample.dat): " zdata 110 read -p "Enter plot style (1-Normal, 2-Bezier, 3-Csplines, 4-Unique, 5-Frequency): " replot_style 111 zplot=/root/Desktop/"${serialnum}-zcavplot.png" 112 113 # replot style 114 case "$replot_style" in 115 1) 116 ptype="" 117 style="Normal" 118 ;; 119 2) 120 ptype="smooth bezier" 121 style="Bezier" 122 ;; 123 3) 124 ptype="smooth csplines" 125 style="Csplines" 126 ;; 127 4) 128 ptype="smooth unique" 129 style="Unique" 130 ;; 131 5) 132 ptype="smooth frequency" 133 style="Frequency" 134 ;; 135 *) 136 ptype="" 137 style="Normal" 138 ;; 139 esac 140 141 read -p "The following data file will be plotted. $zdata" 142 make_script 143 echo "Generating Plot..." 144 gnuplot> $zplot $pscript 145 read -p "Plot script was not deleted. Do you want to delete it now? (1-Yes, 2-No): " pdelete 146 147 # delete plot script or not 148 case "$pdelete" in 149 1) 150 rm -f $pscript 151 exit 0 152 ;; 153 2) 154 exit 0 155 ;; 156 esac 157 } 158 159 # replot or not? 160 if [ -n "$1" ] && [ "$1" == "--replot" ] ; then 161 rplt=1 162 else 163 rplt=0 164 fi 165 166 if [ $rplt -ne 0 ]; then 167 replot 168 fi 169 170 # trap CTRL-C to clean up temp files 171 trap "rm -f $pscript ; exit 0" 2 172 173 # start 174 echo 175 echo "ZCAV Capture v$ver" 176 177 # uniques 178 read -p "Enter the unit's Manufacturer: " mfg 179 read -p "Enter the unit's model: " model 180 read -p "Enter the unit's capacity (i.e. 80GB): " capacity 181 read -p "Enter the unit's interface type (i.e. SAS, SATA): " interface 182 read -p "Enter the unit's serial number: " serialnum 183 read -p "Enter the unit's device name (i.e. /dev/hdc): " device 184 read -p "Enter plot style (1-Normal, 2-Bezier, 3-Csplines, 4-Unique, 5-Frequency): " plot_style 185 read -p "Enter mode (1-Read, 2-Write): " mode 186 187 # setup 188 zplot=/root/Desktop/"${serialnum}-zcavplot.png" 189 zdata=/root/Desktop/"${serialnum}.dat" 190 191 # plot style 192 case "$plot_style" in 193 1) 194 ptype="" 195 style="Normal" 196 ;; 197 2) 198 ptype="smooth bezier" 199 style="Bezier" 200 ;; 201 3) 202 ptype="smooth csplines" 203 style="Csplines" 204 ;; 205 4) 206 ptype="smooth unique" 207 style="Unique" 208 ;; 209 5) 210 ptype="smooth frequency" 211 style="Frequency" 212 ;; 213 *) 214 ptype="" 215 style="Normal" 216 ;; 217 esac 218 219 # mode 220 case "$mode" in 221 1) md="" 222 modeid="Read mode" 223 ;; 224 2) md="-w" 225 modeid="Write mode" 226 ;; 227 *) md="" 228 modeid="Read mode" 229 ;; 230 esac 231 232 # begin capture 233 echo "Running ZCAV in $modeid - this could take a while depending on disk size and interface..." 234 zcav $md $device >> $zdata 235 make_script 236 echo "Generating Plot..." 237 gnuplot> $zplot $pscript 238 rm -f $pscript 239 sleep 1 240 echo "Done."