Also, i can't remove the last 3 characters or the first 55 characters of the output, which is "Timing buffered disk reads: 394 MB in 3.02 seconds = "and "/MB".
The end result should be the number. (for example 256.3)
- Code: Select all
#!/bin/bash
echo "Welcome to this script!"
echo ""
echo "Firstly, you need to check which hard drive is your main hard drive."
echo "The script will now print out the /etc/fstab file, please take a look at the comments and find the partition that represents the root partition."
cat /etc/fstab
echo ""
echo "Please type in the partition."
echo "Eg. /dev/sda1"
read partition
echo ""
echo "Please type the number of tests you want to do on the hard drive."
read tests
clear
echo "Doing $tests tests on $partition."
echo "Press enter to continue."
read enter
clear
average="0"
for (( test=1; test<=$tests; test++ ))
do
echo "Test No. $test"
sudo hdparm -t $partition | tee log.tmp
#Gets the previous sentence
previous=grep -B1 pattern log.tmp
average=$(({previous:55} + $average)) #55 characters before the actual speed indication, adds the actual speed indication to the averga variable
echo ""
done
average=$(($average/$tests))
echo "Your average is $average."




