I have this script which purpose is to find out the average of the writing speed of the chosen harddrive (or the root partition).
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)
#!/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."
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason:Topic automatically closed 6 months after creation. New replies are no longer allowed.
Timing buffered disk reads: 574 MB in 3.01 seconds = 190.88 MB/sec
in the log.tmp file, and then first removes everything before the = sign (include it and the space afterwards) and then removes everything after the final space (including it). What remains is 190.88. You can use the variable $previous now to do further calculations immediately.
Timing buffered disk reads: 574 MB in 3.01 seconds = 190.88 MB/sec
in the log.tmp file, and then first removes everything before the = sign (include it and the space afterwards) and then removes everything after the final space (including it). What remains is 190.88. You can use the variable $previous now to do further calculations immediately.
Might be that summation can't handle the fractional part? Test that by printing the value of $average (and shouldn't that be $sum instead ) inside your loop, to see if it gets updated correctly with each iteration of the loop.
xenopeek wrote:Might be that summation can't handle the fractional part? Test that by printing the value of $average (and shouldn't that be $sum instead ) inside your loop, to see if it gets updated correctly with each iteration of the loop.
#!/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."
echo "Press enter to continue."
echo ""
read enter
clear
echo ""
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
sum=0
number=0
average=0
for (( test=1; test<=$tests; test++ ))
do
echo "Test No. $test"
sudo hdparm -t $partition
#Gets the number from the previous sentence and adds it to average
number=$(grep "^ Timing buffered disk reads:" log.tmp | sed 's/^.* = //' | sed 's/ .*$//')
sum=$(($sum+$number))
echo "$sum"
echo ""
done
echo ""
average=$(($sum/$tests))
echo "Your average is $average MB/sec."
echo "Press enter to quit."
read enter