[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell script reading stdin?



Mike Werner wrote:
> Jim Breton wrote:
> > On Sat, Jun 10, 2000 at 10:54:32PM -0400, Mike Werner wrote:
> > > What I couldn't find was *any* mention of was how to *use* stdin from
> > > within a shell script.  Anyone here ever done anything like this?
> > 
> > 
> > Yes, but this may or may not be suitable for whatever you're doing.  As
> > an example, this would take stdin and pipe it to tr.
> > 
> > #!/bin/sh
> > 
> > cat | tar [A-Z] [a-z]
> > 
> > 
> > There are probably better ways (which I'd also be interested in
> > knowing).  :)
> 
> Thank you!  It appears that this will do the job for me.

It appears I was too optomistic.  It's not working.  Here's the error from
the exim log (originally all one line - wrapped here for clarity):

2000-06-11 14:13:02 131CEI-0002xP-00 ** |/home/picuser/picadmin/message_handle.sh
<picuser@localhost> D=userforward T=address_pipe: Child process of 
address_pipe transport returned 1 from command:
 /home/picuser/picadmin/message_handle.sh

The local username on my box is picuser, and the shell script I'm trying to
write is message_handle.sh
  
> > Fwiw, you could use "exec cat" instead of "cat" if you needed the shell
> > to persist after the cat invocation, but that's a different story.
> 
> I'll keep that in mind, but for this application I don't think it'll
> matter.

I tried both ways, but no difference in the error message received.
  
> > Maybe if you posted what you're trying to do, some better ways of doing
> > it might come to light?
<snipped my lengthy original explanation>

Here's the shell script as it currently stands:

----- start message_handle.sh -----
#!/bin/sh

WD = /home/picuser/picadmin

exec cat > $WD/message.txt
return 0
----- end message_handle.sh -----

As you can see, it is a *very* simple script.

I've also tried the:
cat /dev/stdin > message.txt
that someone else was suggesting.  That gives the same error in the
exim log.

But I think I've finally found a possible solution - I wrote a very
small program in C that reads from stdin and writes to a file.  And
that does work.  So I guess I'll be doing this in C instead of a
shell script.  That's okay though - I could use the practice with C.

Thanks to everyone for the pointers.
-- 
Mike Werner  KA8YSD           |  "Where do you want to go today?"
                              |  "As far from Redmond as possible!"
'91 GS500E                    |
Morgantown WV                 |  Only dead fish go with the flow.



Reply to: