bash script how to parse outputs

I am writing a script to test read/write performance on the network storage, but i need a bit of help to finish the script.

The script is simple:

  1. reloads the nfs mount to clear the cache
  2. write a test file to nfs
  3. record time
  4. read a test file from nfs
  5. record time

I have one remaining issues to solve: parse the output of the time command and store it in a text file.

Time command outputs three values: real 0m0.000s user 0m0.000s sys 0m0.000s

I just want the real time. and one file for read and one file for write.

This is what I have so far:

#!/bin/bash
for i in [`seq 1 20`];
echo "remounting autofs"
/etc/init.d/autofs reload;
wait 5;
echo "write test"
#for write perf
do time dd if=/dev/zero of=/home/nfs_perf_testing/samplefile$i bs=1M count=1024 oflag=direct;
echo "write test done";
wait 5;
echo "read test";
#for read perf;
do time dd if=/home/nfs_perf_testing/samplefile of=/dev/null bs=1M count=1024 iflag=direct;
echo "read test done";
done;

Thank you all

3 Answers

time(1) prints to stderr so you need to redirect it's output to stdout 2>&1, then pipe that to grep to find the line you want grep real. Then lastly use awk to print the column you want awk '{ print $2 }'.

This should put together look like:

(time command_to_time) 2>&1 | grep real | awk '{ print $2 }'
0

Right. Simple enough.

wait doesn't do what you expect. Use sleep here.

for i in `seq 1 20` 

omit the brackets -- they confound the shell here.

BTW: next time consider using iozone or bonnie++. I know iozone has an option to unmount/remount NFS partitions between tests. It also produces data that can be imported into EXCEL and make pretty 3D charts. It also does thing test various block sizes.

Also, RAM caching might become an issue. You might want to have a special boot configuration (in grub) to boot with only so much RAM (like 1MB). See

2

Simple, using grep:

{ time command >/dev/null; } |& grep real

This will output the real time of executing the "command"

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like