Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-27-2004, 06:01 PM   #1
Registered: Apr 2002
Location: Illinois, US
Distribution: Red Hat, Fedora, Yellow Dog, Debian, FreeBSD, Embedix
Posts: 106

Rep: Reputation: 15
redirecting stdin in bash script

this is a silly question, but somehow I can't get this working:
in my /etc/aliases I have a line like this:
fax: "|/test/myscript"

That's supposed to pipe mail sent to account fax to a bash script for processing.

In /test/myscript I have :

cd /tmp
echo $myresult
The line beginning with "myresult" is supposed to set this variable to contain "/tmp/" plus whatever is being output by a python script in /test/
That is supposed to receive incoming message on it's stdin, process it, sotre some data in a file in /tmp and give that file's name on it's stdout to be put in "myresult"

I can't figure out how to feed my e-mail through the bash script into the python script. I've checked my python script by cat myemaildump |, works fine.

I checked silly stuff like paths, permissions, disabled sendmail's smrsh functionality to allow insecure scripts ( the machine sits on private network, not reachable from outside). /var/log/maillog indicates that the message was sent sucessfully to "|/test/myscript", but python script never sees the data.

What am I doing wrong?
Old 01-27-2004, 06:53 PM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Since you are piping into the bash script you will need to use "read" to get the data from stdin then echo that into a pipe to your paython script.
Old 12-08-2011, 03:31 PM   #3
LQ Newbie
Registered: Oct 2007
Posts: 2

Rep: Reputation: 1
You can pipe your script's stdin to the command's stdin with <&0. Like this:
myresult="/tmp/`/test/ <&0`"
I know this is 8 years later but this page ranks highly for "redirect stdin script", etc.
1 members found this post helpful.
Old 12-09-2011, 07:07 AM   #4
Senior Member
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,329

Rep: Reputation: 254Reputation: 254Reputation: 254
Originally Posted by superjer View Post
You can pipe your script's stdin to the command's stdin with <&0. Like this:
myresult="/tmp/`/test/ <&0`"
I know this is 8 years later but this page ranks highly for "redirect stdin script", etc.
The problem is, that after this long time itís hard to tell what the real cause of the problem was and whether it was solved. Did the shellís behavior changed over time? For bash version 3 itís neither necessary to use read for the stdin to feed it to another command or sub-shell, nor to specify <&0 inside a command substitution. Itís mostly used to restore the original stdin after you changed it to something else.
$ cat 
echo $RESULT
$ echo hello | ./ 
No read here, no <&0. I use this in some wrappers to add some lines to an email like:
(echo "*** BEGIN OF ERROR MESSAGE ***"; cat; echo "*** END OF ERROR MESSAGE ***") | mail reuti


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
redirecting /dev/ttyS0 -> stdin goestin Linux - Software 2 10-26-2011 12:34 PM
Redirecting output of background processes after they've been started (BASH) DaneM Programming 18 08-08-2011 10:03 PM
How to create a shell script that reads something from stdin? ricky_ds Programming 2 05-17-2005 06:06 AM
after redirecting stdin still need to read data from keyboard vrikers Programming 4 10-31-2004 07:11 AM
redirecting stdin and stdout with pipes: convincing apps they're for a terminal? prell Programming 1 09-02-2004 07:38 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration