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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
reading XML datas via Shell Script freepal Shell Programming and Scripting 1 02-08-2008 11:52 AM
Shell Script -- problem reading backslash(\)!! rossi143 Shell Programming and Scripting 2 04-04-2007 03:52 AM
reading command output from shell script sri b Shell Programming and Scripting 4 11-16-2006 12:52 AM
Help:error in reading from stdin zhshqzyc High Level Programming 5 09-25-2006 04:58 PM
Reading a table in a shell script luiscarvalheiro Shell Programming and Scripting 13 08-10-2006 07:16 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-11-2008
mmesford mmesford is offline
Registered User
  
 

Join Date: Sep 2008
Location: Seattle
Posts: 4
reading from stdin in a shell script

Hello,

I've managed to get my .procmailrc file to work. At least it triggers a script which creates a file. But the file is empty. How do I get at the data that's been piped? I've done much creative googling to no avail. I belive it should be in stdin, but I can't figure out how to access it.

Thanks
Mike
  #2 (permalink)  
Old 09-12-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,311
When procmail passes it via pipe to your script, your script might look like for example:

Code:
while read LINE; do
   echo ${LINE}    # do something with it here
done

exit 0

Not sure how your script looks like as you didn't show it to us.
  #3 (permalink)  
Old 09-17-2008
mmesford mmesford is offline
Registered User
  
 

Join Date: Sep 2008
Location: Seattle
Posts: 4
Thanks Zaxxon,

I had tried variations of that. I don't really have anything to post because I was stuck at the beginning. Turns out the problem is with my understanding of procmail since your code works fine if I pipe to my script from another script. Here's the procmailrc if anyone has any knowlege of this stuff:

:0 b
|$HOME/test.sh

My understanding is that this should pipe the body of the email to the script test.sh. As it stands right now, the script is triggered but there doesn't appear to be anything piped. I've used your suggestion in a script named "test.sh":

while read LINE; do
echo ${LINE} > t.log
done

exit 0

if I write a small script that says:

echo "test"

save it as t.sh and run it at the command line like this:

./t.sh|./test.sh

then the file t.log is created and contains the line:

test

If I send an email to this mailbox the script test.sh is triggered but the file t.log contains only a blank line. That's where I'm at and I realize this isn't a procmail forum, but any help will be appreciated.
  #4 (permalink)  
Old 07-03-2009
disem disem is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 1
keep it simple people..



Code:
#!/bin/sh
# Converts all lowercase text from
# stdin to uppercase
#
tr '[:lower:]' '[:upper:]' < /dev/stdin

# edward
# ebaddouh@gmail.com

you should call your script as follow:


Code:
$ echo "keep it simple" | myscript.sh
KEEP IT SIMPLE

cheers
  #5 (permalink)  
Old 07-04-2009
kshji's Avatar
kshji kshji is offline
Registered User
  
 

Join Date: Jun 2009
Location: Finland
Posts: 236
Try next cmdline, script caller set the output, script only read from stdin and write to stdout.

Code:
| $HOME/myscript.sh > $HOME/my.log

And myscript.sh, including also how to ex. to set uppercase without external command (ex. tr). Also no need to tell input, if it is stdin.

Code:
#!/usr/bin/ksh
typeset -u input
while read  input
do
     print "$input"
     # if you like to add line to some file, then
     # print some >> somefile
     # single > is overwrite = file include only the lastline
done

But if you like to put all while output to file then >> must be after done = end of while cmd.

Code:
while read line
do
     print some
done >> outfile
# or ex. done | outpipecmd > outfile
# all output, which are done between do-done goto outfile

Script are more generic, if script read from stdin and write to sdtout. Caller make define for input and output. Whole idea of *nix systems/commands - io-redirection and pipes.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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




All times are GMT -4. The time now is 10:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0