The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
capturing line from script output and appending to a file wally_welder Shell Programming and Scripting 6 08-31-2007 12:03 AM
Reading from blocking fifo pipe in shell script victorin Shell Programming and Scripting 4 05-08-2007 08:39 AM
Pipe data to shell script tomjones07 Shell Programming and Scripting 3 03-14-2007 04:50 PM
Capturing a ret val of C obj file in ksh script k_bijitesh High Level Programming 5 05-16-2006 04:20 AM
Capturing shell script command output designflaw Shell Programming and Scripting 2 03-01-2006 01:24 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-02-2005
Registered User
 

Join Date: Nov 2005
Posts: 4
Need help capturing pipe to a file in shell script

The command:
echo "this is some text" | shellscript abc def ghi

My problem:
How to capture "this is some text" so that I can process it,
I.e. capture to a file.

What I'm attemting to do is process the text echo'd into a file after writing the
parameters passed first. No problem capturing abc, def, ghi into environment
variables. I just can't get the text that's being piped to shellscript. I'm trying to
simulate mail/mailx in shellscript.

Thanks in advance for your help.

Heinz
Reply With Quote
Forum Sponsor
  #2  
Old 11-02-2005
Registered User
 

Join Date: Oct 2005
Posts: 9
It sounds like you're trying to use a shell script to read from stdin (this is what you must do to capture "this is some text" from the echo command.)

Try inserting this line into your shell script. This captures the text from echo "this is some text" and stores it into $TEXT

------------------------------------
#!/bin/sh
TEXT=""

for foo in `cat /dev/stdin`
do
TEXT=$foo
done
echo "Captured Text: $TEXT"

-------------------------------------------

A helpful article can be found here:

http://lists.debian.org/debian-user/.../msg01220.html
Reply With Quote
  #3  
Old 11-02-2005
Registered User
 

Join Date: Nov 2005
Posts: 4
Thank you flyingpenguin. Close, but no cigars yet.

No /dev/stdin in interix (MS Win2003 Services for Unix).

Searching for equivilant. At least now I have something to search for.

heinz
Reply With Quote
  #4  
Old 11-02-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
The first command in the script must do something with the piped input. So maybe use something like this....
Code:
#!/usr/bin/ksh

cat > /tmp/captured.txt
:
Reply With Quote
  #5  
Old 11-02-2005
Registered User
 

Join Date: Nov 2005
Posts: 4
That did it Ygor.

I could've sworn I tried that early in the game, but guess not.

Thank you very much.
Reply With Quote
  #6  
Old 11-03-2005
Registered User
 

Join Date: Feb 2005
Location: Columbus OH
Posts: 133
Use tee command

Something like this would work

Code:
echo "this is some text" | tee file_name | shellscript abc def ghi
Jerardfjay
Reply With Quote
  #7  
Old 11-03-2005
Registered User
 

Join Date: Nov 2005
Posts: 4
Yes, that would work, but not in may case as I can't change the command structure itself. I had to replace mailx as for some reason it broke and I found it easier to replace it than to dig into why it broke. That will be done some other time when we can risk possible downtime.

The cat > /tmp/file.txt did the trick. I'm still shaking my head as to what I did (or didn't) do right initially as I knew that should work. Maybe I didn't have it in as first command. Anyways, don't care as I have it working now :-)

In case you're wondering, I found eemailer that runs as a service on Win2003 Server so I replaced mailx with my own, I.e. the script, which just builds the mail message and deposits it into the directory eemailer watches. Unix (interix) on Win Server is turning out to be a good platform for us (knock on wood).

Thanks again everyone, especially Ygor who had the winner :-)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0