nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

How can I get some specific characters of dd command output

This is a discussion on How can I get some specific characters of dd command output within the Shell scripting forums, part of the Development/Scripting category; Hi all!, ---here is my sample script---- echo "Enter the size of the file to be created: " read size ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 05-23-2006, 04:45 PM
Member
User
 
Join Date: Jun 2005
Posts: 45
Rep Power: 0
warren
Default How can I get some specific characters of dd command output

Hi all!,

---here is my sample script----
echo "Enter the size of the file to be created: "
read size
echo "How many files will be created? "
read quantity
i=1
while [ $i -le $quantity ]
do
dd if=/dev/zero of=file$i bs=1M count=$size 2> /dev/null
echo "File$i created...."
i=`expr $i + 1`
done

the output is
File1 created....
File2 created....

here is the output of dd command:
dd if=/dev/zero of=file1 bs=1M count=1
3+0 records in
3+0 records out
3145728 bytes (3.1 MB) copied, 0.088105 seconds, 35.7 MB/s

How can I get the character "35.7 MB/s" or maybe the whole 3rd line and then I can append this to the output of the script.
like:
File1 created....35.7 MB/s
File2 created....35.7 MB/s

thanks for any help....
warren
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-23-2006, 06:22 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Hmm...

Try as follows (may be in your loop):

Code:
(dd if=/dev/zero of=file1 bs=1M count=1) 2>/tmp/fsize.tmp
grep copied /tmp/fsize.tmp
>/tmp/fsize.tmp
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #3 (permalink)  
Old 05-24-2006, 04:59 PM
Member
User
 
Join Date: Jun 2005
Posts: 45
Rep Power: 0
warren
Default

ok, so we need to create temporary file..
I have here my sample script, its not that good but it works
I search the line that contains the character MB then get the last two words.

( dd if=/dev/zero of=file$i bs=1M count=$size ) 2> tmp.txt
echo "File$i created..`awk '/MB/ {print}' tmp.txt | awk '{print $8" "$9}'`"

my output now is :
File1 created...9.5 MB/s

its not that useful if the files are small because it will print so fast but in large files, its very useful because you can have an idea about the performance of your system.

thanks a lot,
warren
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Linux shutdown computer specific time chiku Linux software 1 04-27-2007 05:53 PM
Select specific rows c341 Shell scripting 6 01-18-2007 03:04 AM
How can I redirect the output of time command to file warren Linux software 13 08-25-2006 12:17 PM
deleting files created with special characters in solaris Solaris/OpenSolaris 1 01-11-2006 11:59 PM
Script to extract a specific row of data ricc Shell scripting 1 11-15-2005 03:29 PM


All times are GMT +5.5. The time now is 09:10 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36