M
M
mars natsuhiboshi2015-01-08 16:16:43
Perl
mars natsuhiboshi, 2015-01-08 16:16:43

How to change the word "on the fly" listening to the socket, and immediately sending via sendmail?

The perl script listens to a socket, receives textual information, with a certain periodicity, and immediately sends the received information via sendmail to a certain group of addresses. The question is how to edit the contents of a future letter on the fly by sending via sendmail and actually send a new version already?
I am attaching the script

#!/usr/bin/perl -w
    use strict;
    use IO::Socket;

    my($server, $newmsg, $max_len, $server_port, $cmd_mail, $to_email, $subject,);
    $max_len = 900;
    $server_port = 50001;
    $cmd_mail = "/usr/sbin/sendmail -t";
    $to_email = "user\@mail";
    $subject = "State warn!";

    $server = IO::Socket::INET->new(LocalPort=>$server_port, Broadcast=>0, Proto=>"udp")
    or die "Error starting UDP Server on port $server_port: [email protected]\n";
    print "UDP Server started on port $server_port\n";
    $newmsg = "";
    while($server->recv($newmsg,$max_len)){
    if($newmsg){
    my($port, $ipaddr) = sockaddr_in($server->peername);
    $ipaddr = 127.0.0.1;
    print "Received: $newmsg \n";
    open (SENDMAIL, "|$cmd_mail") || die "ERROR: Can not run sendmail";
    print SENDMAIL "MIME-Version: 1.0\n";
    print SENDMAIL "Content-Type: text/plain; charset=\"utf8\"\n";
    print SENDMAIL "Content-Transfer-Encoding: 8bit\n";
    print SENDMAIL "To: $to_email\n";
    print SENDMAIL "Subject: $subject\n\n";
    print SENDMAIL $newmsg . "\n";
close (SENDMAIL)
    }
    }

    die "recv: $!";

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mars natsuhiboshi, 2015-01-08
@mars_unique

I dug in the wrong direction, like a stubborn ram, thanks figured it out.
$newmsg =~ s/Old/New/g;

R
Rsa97, 2015-01-08
@Rsa97

So, in fact, edit $newmsg before the output as you need, and that's it.
If you want everything to be done for you, then go freelancing .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question