Re: filter feedback/help request

2019-07-05 Thread Edgar Pettijohn
Turned out to be a line buffering issue. The following works.

#!/usr/bin/perl

open(my $fh, '>', '/tmp/test.txt');

select(STDOUT);
$|++;
select($fh);
$|++;

print STDOUT "register|report|smtp-in|*\n";
print STDOUT "register|ready\n";

while ( my $line = <> ) {
print $fh "$line";
}

close $fh;

0;

-- 
You received this mail because you are subscribed to misc@opensmtpd.org
To unsubscribe, send a mail to: misc+unsubscr...@opensmtpd.org



Re: filter feedback/help request

2019-07-05 Thread Marc Chantreux
hello,

as it's not relatted to opensmtp, i don't know if replying is ok. please
let me know if it wasn't.

  > Here is a basic shell script that works.
  
  #!/bin/sh
  
  echo "register|report|smtp-in|*"
  echo "register|ready"
  
  while read -r line;
  do
echo "$line" >> /tmp/test.txt
  done

are you aware you just missed a use of cat?

  #!/bin/sh
  
  echo "register|report|smtp-in|*"
  echo "register|ready"
  cat >> /tmp/test.txt
  
> However, the perl and lua equivalents do nothing.

* I don't know about lua but as you used '>>' in your shell script, you
  have to use it in the perl one to get the same behavior.
* also using print FH use the global FH (old school perl)..
  don't do that with serious scripts but you can write:

  #!/usr/bin/perl
  use autodie;
  open FH,'>/tmp/test.txt';
  print
( "register|report|smtp-in|*\n"
, "register|ready\n" );
  print FH while <>;

regards
marc

-- 
You received this mail because you are subscribed to misc@opensmtpd.org
To unsubscribe, send a mail to: misc+unsubscr...@opensmtpd.org



filter feedback/help request

2019-07-04 Thread Edgar Pettijohn
I've been playing around with filters for a few hours, but I can't seem to get 
perl or lua scripts to work.

Here is a basic shell script that works.

#!/bin/sh

echo "register|report|smtp-in|*" 
echo "register|ready"

while read -r line;
do
echo "$line" >> /tmp/test.txt
done

However, the perl and lua equivalents do nothing. I don't see anything in the 
logs, but not sure if any filtering causes log entries to begin with. I suppose 
I could just use perl in my shell script, but overall it would be better for 
the perl to just work. I don't have much experience with lua, just wanted to 
test something else when I couldn't get perl working. I also tested the 
filter-eventlog and the filters Joerg posted. All of which worked in my very 
basic testing/experimenting. Thanks in advance for any help.

Edgar

#!/usr/bin/perl

open (my $fh, '>', '/tmp/test.txt') or die $!;

print "register|report|smtp-in|*\n";
print "register|ready\n";

while ( <> ) {
print $fh;
}

0;

#!/usr/local/bin/lua53

io.write("register|report|smtp-in|*\n")
io.write("register|ready\n")

out = io.open("/tmp/test.txt", "w")
io.output(out)

while true do
local line = io.read("*line")
if line == nil then break end
io.write(line)
end

-- 
You received this mail because you are subscribed to misc@opensmtpd.org
To unsubscribe, send a mail to: misc+unsubscr...@opensmtpd.org