Take the 2-minute tour ×

I have setup an alias in /etc/aliases so that each time an email comes in to a specific address, the text of the email is sent to a Ruby script. Like so:

example: |/etc/smrsh/my_script.rb

I need to know how to read the piped data in my Ruby script.. I have written a simple Perl script that can read the data.. just can't figure out how to do it in Ruby.

Here is the relevant lines in the Perl script:

my $fout = "/tmp/email.out";

open( EM, ">$fout" );

while( <> )  {
    print EM "$_\n";
share|improve this question
add comment

1 Answer

You can use STDIN to read your pided data. The equivalent of your Perl code would be something like:

out = File.open("/tmp/email.out", "a+")
STDIN.each do |line|
  out.puts line
share|improve this answer
This worked great, thank you. As a side note, in order to get the alias to work properly, I had to create symlink to the ruby binary in /etc/smrsh and then define the alias as: my_alias: "|/etc/smrsh/ruby /etc/smrsh/my_script.rb" And that did it! Thanks! –  Jason Palmer May 14 '09 at 16:08
add comment

Your Answer

