tags:

views:

33

answers:

1

Hello,

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( <> ) { chomp; print EM "$_\n"; }

+2  A: 

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
end
molf
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!