Help needed with dd command
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Help needed with dd command




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Help needed with dd command  
John


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 06:36 AM

I'm getting the following errors when I run the following script
(named sedscript.sh):

#!/bin/ksh
cat <(dd if=invfile bs=1 count=359) <(print -n "ABCDE") <(dd
if=invfile skip=364 bs=1) > outputfile.txt

+ dd if=invfile bs=1 count=359
+ cat /dev/fd/4 /dev/fd/5 /dev/fd/6 invfile  # HUH?????????????
+ print -n ABCDE
+ dd if=invfile skip=364 bs=1
+ 1> outputfile.txt
sedscript.sh[2]: cat: /dev/fd/4: cannot open [No such file or
directory]
sedscript.sh[2]: cat: /dev/fd/5: cannot open [No such file or
directory]
sedscript.sh[2]: cat: /dev/fd/6: cannot open [No such file or
directory]
359+0 records in
359+0 records out

Can someone see what I've typed incorrectly in this script?  What's
the deal with all the cat /dev/fd errors and why ABCDE is still not
being inserting into my file?





[ Post a follow-up to this message ]



    Re: Help needed with dd command  
Bill Marcum


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 09:36 AM

["Followup-To:" header set to comp.unix.admin.]
On 11 Feb 2004 06:25:07 -0800, John
<pokechoppe@aol.com> wrote:
> I'm getting the following errors when I run the following script
> (named sedscript.sh):
>
> #!/bin/ksh
> cat <(dd if=invfile bs=1 count=359) <(print -n "ABCDE") <(dd
> if=invfile skip=364 bs=1) > outputfile.txt
>
What flavor of Unix?  What version of ksh?  It seems like you may have
found a bug, the question is, do you need to update your software or
report the bug, and to whom (kornshell.com or the pdksh maintainers)?

You could rewrite your script without using <( ):
dd if=invfile bs=1 count=359 > outputfile.txt
print -n "ABCDE" >> outputfile.txt
dd if=invfile skil=364 bs=1 >> outputfile.txt

--
Think of your family tonight.  Try to crawl home after the computer crashes.





[ Post a follow-up to this message ]



    Re: Help needed with dd command  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-11-04 11:36 AM

On Wed, 11 Feb 2004 at 14:25 GMT, John wrote:
> I'm getting the following errors when I run the following script
> (named sedscript.sh):
>
> #!/bin/ksh
> cat <(dd if=invfile bs=1 count=359) <(print -n "ABCDE") <(dd
> if=invfile skip=364 bs=1) > outputfile.txt
>
> + dd if=invfile bs=1 count=359
> + cat /dev/fd/4 /dev/fd/5 /dev/fd/6 invfile  # HUH?????????????
> + print -n ABCDE
> + dd if=invfile skip=364 bs=1
> + 1> outputfile.txt
> sedscript.sh[2]: cat: /dev/fd/4: cannot open [No such file or
> directory]
> sedscript.sh[2]: cat: /dev/fd/5: cannot open [No such file or
> directory]
> sedscript.sh[2]: cat: /dev/fd/6: cannot open [No such file or
> directory]
> 359+0 records in
> 359+0 records out
>
> Can someone see what I've typed incorrectly in this script?  What's
> the deal with all the cat /dev/fd errors and why ABCDE is still not
> being inserting into my file?

Don't make it more complicated than necessary:

{
dd if=invfile bs=1 count=359
printf "ABCDE"
dd if=invfile skip=364 bs=1
} > outputfile.txt

--
Chris F.A. Johnson                        http://cfaj.freeshell.org
 ========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License





[ Post a follow-up to this message ]



    Re: Help needed with dd command  
Doug Freyburger


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-12-04 06:36 AM

John wrote:
>
> I'm getting the following errors when I run the following script
> (named sedscript.sh):
>
> #!/bin/ksh
> cat <(dd if=invfile bs=1 count=359) <(print -n "ABCDE") <(dd
> if=invfile skip=364 bs=1) > outputfile.txt
>
> + dd if=invfile bs=1 count=359
> + cat /dev/fd/4 /dev/fd/5 /dev/fd/6 invfile  # HUH?????????????

Is this Solaris?  /dev/ file discriptors / file number makes sense
in this context but I didn't know that Korn shell used them as
strings in commands.

But think about what you did.  You opened 3 subshells producing
output and set them each to be input to the cat.  Sure enough cat
reads the files on the command lines.  Picking 4, 5 and 6 only
says the shell had something else open for 2 and 3 before then.

I'm not comfortable with doing more than one redirection of input,
though.  It sets up a race condition: Commands in parens or back
ticks get run asynchronously without specified order or timing.
Arrow redirection happens the "the" command is started.  But the
cat is "the" command in that case, not the subshells.

> + print -n ABCDE
> + dd if=invfile skip=364 bs=1
> + 1> outputfile.txt
> sedscript.sh[2]: cat: /dev/fd/4: cannot open [No such file or
> directory]
> sedscript.sh[2]: cat: /dev/fd/5: cannot open [No such file or
> directory]
> sedscript.sh[2]: cat: /dev/fd/6: cannot open [No such file or
> directory]
> 359+0 records in
> 359+0 records out

So it appears to me that it set up the redirections, launched the
cat attached to them, expected the cat to wait for its input, and
on a separate timetable started up the other images in the pipe.
Since it launched the first dd before the cat, I'm surprised it
failed on /dev/fd/4, but I'm not surprised that it failed on the
other two.

> Can someone see what I've typed incorrectly in this script?  What's
> the deal with all the cat /dev/fd errors and why ABCDE is still not
> being inserting into my file?

Work on a simpler I/O redirection scheme.  The man page for the
shell only gives examples of single arrow commands, so only use single
arrow commands.  Bundle all of the parts into a single subshell.

Even better, run the 3 subcommands in order.  dd > outputfile,txt,
print >> outputfile.txt, dd >> outpputfile.txt

When fanced with the choice between fancy and coll looking, or
going towards the center of how shells are designed and ugly, move
towards the center of the design.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:45 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register